Skip to content

Commit 7b72288

Browse files
committed
docs: add LLM adapters to documentation navigation
- Add link in docs/index.md Getting Started section - Add entry in mkdocs.yml navigation - Add reference in README.md Advanced Usage section - Register example script in pyproject.toml
1 parent 9725fc7 commit 7b72288

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,40 @@ if __name__ == "__main__":
24872487
asyncio.run(main())
24882488
```
24892489

2490+
### Converting MCP Tools for LLM Providers
2491+
2492+
When integrating MCP tools with LLM providers (like Gemini, GPT-4, or Claude), you need to convert MCP tool schemas to the provider's format. The SDK makes this easy with comprehensive documentation and examples.
2493+
2494+
See the [LLM Provider Adapters guide](https://modelcontextprotocol.github.io/python-sdk/llm-adapters/) for:
2495+
2496+
- Complete adapter implementations for Gemini, OpenAI, and Anthropic Claude
2497+
- Best practices for schema conversion
2498+
- Error handling patterns
2499+
- Advanced conversion techniques
2500+
2501+
<!-- snippet-source examples/snippets/clients/llm_adapter_example.py -->
2502+
```python
2503+
"""Example: Convert MCP tools to various LLM provider formats."""
2504+
2505+
from mcp import ClientSession, StdioServerParameters, types
2506+
from mcp.client.stdio import stdio_client
2507+
2508+
# After connecting to an MCP server and listing tools:
2509+
tools_response = await session.list_tools()
2510+
2511+
# Convert to Gemini format
2512+
gemini_tools = [to_gemini_function_declaration(tool) for tool in tools_response.tools]
2513+
2514+
# Convert to OpenAI format
2515+
openai_tools = [to_openai_function(tool) for tool in tools_response.tools]
2516+
2517+
# Convert to Claude format
2518+
claude_tools = [to_claude_tool(tool) for tool in tools_response.tools]
2519+
```
2520+
2521+
_Full example: [examples/snippets/clients/llm_adapter_example.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/clients/llm_adapter_example.py)_
2522+
<!-- /snippet-source -->
2523+
24902524
### MCP Primitives
24912525

24922526
The MCP protocol defines three core primitives that servers can implement:
@@ -2512,6 +2546,7 @@ MCP servers declare capabilities during initialization:
25122546
## Documentation
25132547

25142548
- [API Reference](https://modelcontextprotocol.github.io/python-sdk/api/)
2549+
- [LLM Provider Adapters](https://modelcontextprotocol.github.io/python-sdk/llm-adapters/) - Convert MCP tools to LLM provider formats
25152550
- [Model Context Protocol documentation](https://modelcontextprotocol.io)
25162551
- [Model Context Protocol specification](https://modelcontextprotocol.io/specification/latest)
25172552
- [Officially supported servers](https://github.com/modelcontextprotocol/servers)

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ npx -y @modelcontextprotocol/inspector
6161
2. **[Learn concepts](concepts.md)** - understand the three primitives and architecture
6262
3. **[Explore authorization](authorization.md)** - add security to your servers
6363
4. **[Use low-level APIs](low-level-server.md)** - for advanced customization
64+
5. **[Create LLM adapters](llm-adapters.md)** - convert MCP tools to LLM provider formats
6465

6566
## API Reference
6667

examples/snippets/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ direct-execution-server = "servers.direct_execution:main"
2222
display-utilities-client = "clients.display_utilities:main"
2323
oauth-client = "clients.oauth_client:run"
2424
elicitation-client = "clients.url_elicitation_client:run"
25+
llm-adapter-example = "clients.llm_adapter_example:run"

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ nav:
1717
- Concepts: concepts.md
1818
- Low-Level Server: low-level-server.md
1919
- Authorization: authorization.md
20+
- LLM Provider Adapters: llm-adapters.md
2021
- Testing: testing.md
2122
- API Reference: api.md
2223

0 commit comments

Comments
 (0)