# Install Page Systems in a LangChain or LangGraph agent

Load the Page Systems MCP tools with LangChain's MCP adapters and give them to `create_agent` (a LangGraph agent).

Tested with `langchain` 1.4.4, `langchain-mcp-adapters` 0.3.2 and `langgraph` 1.2.14 (Python), and `langchain` 1.5.16 with `@langchain/mcp-adapters` 2.0.1 (JavaScript).

## 1. Set your API key

Create a key in the [dashboard](https://app.pagesystems.ai/dashboard/keys) (it starts with `ap_live_` and is shown once) and set it where your agent runs. Never commit it.

```bash
export PAGE_SYSTEMS_API_KEY=ap_live_...
```

## 2. Python

```bash
pip install langchain langchain-mcp-adapters langgraph
```

```python
import os
import urllib.request

from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.checkpoint.memory import InMemorySaver

skill = urllib.request.urlopen("https://pagesystems.ai/v1/skill").read().decode()  # once, at startup

client = MultiServerMCPClient({
    "page-systems": {
        "transport": "http",
        "url": "https://pagesystems.ai/mcp",
        "headers": {"Authorization": f"Bearer {os.environ['PAGE_SYSTEMS_API_KEY']}"},
    }
})
agent = create_agent(
    model,
    await client.get_tools(),
    system_prompt=your_instructions + "\n\n" + skill,
    checkpointer=InMemorySaver(),
)
result = await agent.ainvoke({"messages": [{"role": "user", "content": user_message}]}, {"configurable": {"thread_id": conversation_id}})
```

## 3. JavaScript

```bash
npm install langchain @langchain/mcp-adapters @langchain/langgraph
```

```ts
import { createAgent } from 'langchain';
import { MultiServerMCPClient } from '@langchain/mcp-adapters';
import { MemorySaver } from '@langchain/langgraph';

const skill = await fetch('https://pagesystems.ai/v1/skill').then((r) => r.text()); // once, at startup
const client = new MultiServerMCPClient({
  mcpServers: {
    'page-systems': {
      transport: 'http',
      url: 'https://pagesystems.ai/mcp',
      headers: { Authorization: `Bearer ${process.env.PAGE_SYSTEMS_API_KEY}` },
    },
  },
});
const agent = createAgent({
  model,
  tools: await client.getTools(),
  systemPrompt: [yourInstructions, skill].join('\n\n'),
  checkpointer: new MemorySaver(),
});
const result = await agent.invoke({ messages: [{ role: 'user', content: userMessage }] }, { configurable: { thread_id: conversationId } });
```

## 4. Keep the conversation

The answer arrives in a later turn. A checkpointer with the same `thread_id` keeps the history, so the model can call `get_page_result` with the page id it already has. `InMemorySaver` / `MemorySaver` lose it on restart; use a persistent checkpointer in production.

## 5. Check it works

Ask your agent something a page answers better than chat, for example "Ask Sam which of 9:00, 11:00 or 14:00 next Tuesday works for a call." It should send a link. Open it, pick a time, submit, then ask the agent what Sam picked: it reads the answer with `get_page_result`.
