Skip to content

Commit 5e79fa6

Browse files
authored
better mcp gateway/auth docs (#1580)
1 parent f4749b1 commit 5e79fa6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/langsmith/agent-builder-mcp-framework.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,53 @@ Tools with `auth_provider` must:
120120
- Have `context: Context` as the first parameter
121121
- Specify at least one scope
122122
- Use `context.token` to make authenticated API calls
123+
124+
## Using as an MCP gateway
125+
126+
The LangSmith Tool Server can act as an MCP gateway, aggregating tools from multiple MCP servers into a single endpoint. Configure MCP servers in your `toolkit.toml`:
127+
128+
```toml
129+
[toolkit]
130+
name = "my-toolkit"
131+
tools = "./my_toolkit/__init__.py:TOOLS"
132+
133+
[[mcp_servers]]
134+
name = "weather"
135+
transport = "streamable_http"
136+
url = "http://localhost:8001/mcp/"
137+
138+
[[mcp_servers]]
139+
name = "math"
140+
transport = "stdio"
141+
command = "python"
142+
args = ["-m", "mcp_server_math"]
143+
```
144+
145+
All tools from connected MCP servers are exposed through your server's `/mcp` endpoint. MCP tools are prefixed with their server name to avoid conflicts (e.g., `weather.get_forecast`, `math.add`).
146+
147+
## Custom authentication
148+
149+
Custom authentication allows you to validate requests and integrate with your identity provider. Define an authentication handler in your `auth.py` file:
150+
151+
```python
152+
from langsmith_tool_server import Auth
153+
154+
auth = Auth()
155+
156+
@auth.authenticate
157+
async def authenticate(authorization: str = None) -> dict:
158+
"""Validate requests and return user identity."""
159+
if not authorization or not authorization.startswith("Bearer "):
160+
raise auth.exceptions.HTTPException(
161+
status_code=401,
162+
detail="Unauthorized"
163+
)
164+
165+
token = authorization.replace("Bearer ", "")
166+
# Validate token with your identity provider
167+
user = await verify_token_with_idp(token)
168+
169+
return {"identity": user.id}
170+
```
171+
172+
The handler runs on every request and must return a dict with `identity` (and optionally `permissions`).

0 commit comments

Comments
 (0)