Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,7 @@
"langsmith/agent-builder",
"langsmith/agent-builder-setup",
"langsmith/agent-builder-tools",
"langsmith/agent-builder-mcp-framework",
"langsmith/agent-builder-slack-app"
]
},
Expand Down
122 changes: 122 additions & 0 deletions src/langsmith/agent-builder-mcp-framework.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: LangSmith Tool Server
sidebarTitle: MCP Framework
mode: wide
---

The LangSmith Tool Server is our MCP Framework that powers the tools available in the LangSmith Agent Builder. This framework enables you to build and deploy custom tools that can be integrated with your agents. It provides a standardized way to create, deploy, and manage tools with built-in authentication and authorization.

The PyPi package that defines the framework is available [here](https://pypi.org/project/langsmith-tool-server/).

## Quick start

Install the LangSmith Tool Server and LangChain CLI:

```bash
pip install langsmith-tool-server
pip install langchain-cli-v2
```

Create a new toolkit:

```bash
langchain tools new my-toolkit
cd my-toolkit
```

This creates a toolkit with the following structure:

```
my-toolkit/
├── pyproject.toml
├── toolkit.toml
└── my_toolkit/
├── __init__.py
├── auth.py
└── tools/
├── __init__.py
└── ...
```

Define your tools using the `@tool` decorator:

```python
from langsmith_tool_server import tool

@tool
def hello(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"

@tool
def add(x: int, y: int) -> int:
"""Add two numbers."""
return x + y

TOOLS = [hello, add]
```

Run the server:

```bash
langchain tools serve
```

Your tool server will start on `http://localhost:8000`.

## Simple client example

Here's a simple example that lists available tools and calls the `add` tool:

```python
import asyncio
import aiohttp

async def mcp_request(url: str, method: str, params: dict = None):
async with aiohttp.ClientSession() as session:
payload = {"jsonrpc": "2.0", "method": method, "params": params or {}, "id": 1}
async with session.post(f"{url}/mcp", json=payload) as response:
return await response.json()

async def main():
url = "http://localhost:8000"

tools = await mcp_request(url, "tools/list")
print(f"Tools: {tools}")

result = await mcp_request(url, "tools/call", {"name": "add", "arguments": {"a": 5, "b": 3}})
print(f"Result: {result}")

asyncio.run(main())
```

## Adding OAuth authentication

For tools that need to access third-party APIs (like Google, GitHub, Slack, etc.), you can use OAuth authentication with [Agent Auth](/langsmith/agent-auth).

Before using OAuth in your tools, you'll need to configure an OAuth provider in your LangSmith workspace settings. See the [Agent Auth documentation](/langsmith/agent-auth) for setup instructions.

Once configured, specify the `auth_provider` in your tool decorator:

```python
from langsmith_tool_server import tool, Context
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build

@tool(
auth_provider="google",
scopes=["https://www.googleapis.com/auth/gmail.readonly"],
integration="gmail"
)
async def read_emails(context: Context, max_results: int = 10) -> str:
"""Read recent emails from Gmail."""
credentials = Credentials(token=context.token)
service = build('gmail', 'v1', credentials=credentials)
# ... Gmail API calls
return f"Retrieved {max_results} emails"
```

Tools with `auth_provider` must:
- Have `context: Context` as the first parameter
- Specify at least one scope
- Use `context.token` to make authenticated API calls