Spaces:
Running
Running
Merge pull request #790 from jlowin/llm-docs
Browse files- docs/assets/images/tutorial-rest-api-result.png +3 -0
- docs/docs.json +3 -1
- docs/tutorials/mcp.mdx +120 -0
- docs/tutorials/rest-api.mdx +203 -0
docs/assets/images/tutorial-rest-api-result.png
ADDED
|
Git LFS Details
|
docs/docs.json
CHANGED
|
@@ -134,7 +134,9 @@
|
|
| 134 |
"anchor": "Tutorials",
|
| 135 |
"icon": "graduation-cap",
|
| 136 |
"pages": [
|
| 137 |
-
"tutorials/
|
|
|
|
|
|
|
| 138 |
]
|
| 139 |
},
|
| 140 |
{
|
|
|
|
| 134 |
"anchor": "Tutorials",
|
| 135 |
"icon": "graduation-cap",
|
| 136 |
"pages": [
|
| 137 |
+
"tutorials/mcp",
|
| 138 |
+
"tutorials/create-mcp-server",
|
| 139 |
+
"tutorials/rest-api"
|
| 140 |
]
|
| 141 |
},
|
| 142 |
{
|
docs/tutorials/mcp.mdx
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: "What is the Model Context Protocol (MCP)?"
|
| 3 |
+
sidebarTitle: "What is MCP?"
|
| 4 |
+
description: "An introduction to the core concepts of the Model Context Protocol (MCP), explaining what it is, why it's useful, and how it works."
|
| 5 |
+
icon: "diagram-project"
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
The Model Context Protocol (MCP) is an open standard designed to solve a fundamental problem in AI development: how can Large Language Models (LLMs) reliably and securely interact with external tools, data, and services?
|
| 9 |
+
|
| 10 |
+
It's the **bridge between the probabilistic, non-deterministic world of AI and the deterministic, reliable world of your code and data.**
|
| 11 |
+
|
| 12 |
+
While you could build a custom REST API for your LLM, MCP provides a specialized, standardized "port" for AI-native communication. Think of it as **USB-C for AI**: a single, well-defined interface for connecting any compliant LLM to any compliant tool or data source.
|
| 13 |
+
|
| 14 |
+
This guide provides a high-level overview of the protocol itself. We'll use **FastMCP**, the leading Python framework for MCP, to illustrate the concepts with simple code examples.
|
| 15 |
+
|
| 16 |
+
## Why Do We Need a Protocol?
|
| 17 |
+
|
| 18 |
+
With countless APIs already in existence, the most common question is: "Why do we need another one?"
|
| 19 |
+
|
| 20 |
+
The answer lies in **standardization**. The AI ecosystem is fragmented. Every model provider has its own way of defining and calling tools. MCP's goal is to create a common language that offers several key advantages:
|
| 21 |
+
|
| 22 |
+
1. **Interoperability:** Build one MCP server, and it can be used by any MCP-compliant client (Claude, Gemini, OpenAI, custom agents, etc.) without custom integration code. This is the protocol's most important promise.
|
| 23 |
+
2. **Discoverability:** Clients can dynamically ask a server what it's capable of at runtime. They receive a structured, machine-readable "menu" of tools and resources.
|
| 24 |
+
3. **Security & Safety:** MCP provides a clear, sandboxed boundary. An LLM can't execute arbitrary code on your server; it can only *request* to run the specific, typed, and validated functions you explicitly expose.
|
| 25 |
+
4. **Composability:** You can build small, specialized MCP servers and combine them to create powerful, complex applications.
|
| 26 |
+
|
| 27 |
+
## Core MCP Components
|
| 28 |
+
|
| 29 |
+
An MCP server exposes its capabilities through three primary components: Tools, Resources, and Prompts.
|
| 30 |
+
|
| 31 |
+
### Tools: Executable Actions
|
| 32 |
+
|
| 33 |
+
Tools are functions that the LLM can ask the server to execute. They are the action-oriented part of MCP.
|
| 34 |
+
|
| 35 |
+
In the spirit of a REST API, you can think of **Tools as being like `POST` requests.** They are used to *perform an action*, *change state*, or *trigger a side effect*, like sending an email, adding a user to a database, or making a calculation.
|
| 36 |
+
|
| 37 |
+
With FastMCP, creating a tool is as simple as decorating a Python function.
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
from fastmcp import FastMCP
|
| 41 |
+
|
| 42 |
+
mcp = FastMCP()
|
| 43 |
+
|
| 44 |
+
# This function is now an MCP tool named "get_weather"
|
| 45 |
+
@mcp.tool
|
| 46 |
+
def get_weather(city: str) -> dict:
|
| 47 |
+
"""Gets the current weather for a specific city."""
|
| 48 |
+
# In a real app, this would call a weather API
|
| 49 |
+
return {"city": city, "temperature": "72F", "forecast": "Sunny"}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
[**Learn more about Tools →**](/servers/tools)
|
| 53 |
+
|
| 54 |
+
### Resources: Read-Only Data
|
| 55 |
+
|
| 56 |
+
Resources are data sources that the LLM can read. They are used to load information into the LLM's context, providing it with knowledge it doesn't have from its training data.
|
| 57 |
+
|
| 58 |
+
Following the REST API analogy, **Resources are like `GET` requests.** Their purpose is to *retrieve information* idempotently, ideally without causing side effects. A resource can be anything from a static text file to a dynamic piece of data from a database. Each resource is identified by a unique URI.
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
from fastmcp import FastMCP
|
| 62 |
+
|
| 63 |
+
mcp = FastMCP()
|
| 64 |
+
|
| 65 |
+
# This function provides a resource at the URI "system://status"
|
| 66 |
+
@mcp.resource("system://status")
|
| 67 |
+
def get_system_status() -> dict:
|
| 68 |
+
"""Returns the current operational status of the service."""
|
| 69 |
+
return {"status": "all systems normal"}
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
#### Resource Templates
|
| 73 |
+
|
| 74 |
+
You can also create **Resource Templates** for dynamic data. A client could request `users://42/profile` to get the profile for a specific user.
|
| 75 |
+
|
| 76 |
+
```python
|
| 77 |
+
from fastmcp import FastMCP
|
| 78 |
+
|
| 79 |
+
mcp = FastMCP()
|
| 80 |
+
|
| 81 |
+
# This template provides user data for any given user ID
|
| 82 |
+
@mcp.resource("users://{user_id}/profile")
|
| 83 |
+
def get_user_profile(user_id: str) -> dict:
|
| 84 |
+
"""Returns the profile for a specific user."""
|
| 85 |
+
# Fetch user from a database...
|
| 86 |
+
return {"id": user_id, "name": "Zaphod Beeblebrox"}
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
[**Learn more about Resources & Templates →**](/servers/resources)
|
| 90 |
+
|
| 91 |
+
### Prompts: Reusable Instructions
|
| 92 |
+
|
| 93 |
+
Prompts are reusable, parameterized message templates. They provide a way to define consistent, structured instructions that a client can request to guide the LLM's behavior for a specific task.
|
| 94 |
+
|
| 95 |
+
```python
|
| 96 |
+
from fastmcp import FastMCP
|
| 97 |
+
|
| 98 |
+
mcp = FastMCP()
|
| 99 |
+
|
| 100 |
+
@mcp.prompt
|
| 101 |
+
def summarize_text(text_to_summarize: str) -> str:
|
| 102 |
+
"""Creates a prompt asking the LLM to summarize a piece of text."""
|
| 103 |
+
return f"""
|
| 104 |
+
Please provide a concise, one-paragraph summary of the following text:
|
| 105 |
+
|
| 106 |
+
{text_to_summarize}
|
| 107 |
+
"""
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
[**Learn more about Prompts →**](/servers/prompts)
|
| 111 |
+
|
| 112 |
+
## Advanced Capabilities
|
| 113 |
+
|
| 114 |
+
Beyond the core components, MCP also supports more advanced interaction patterns, such as a server requesting that the *client's* LLM generate a completion (known as **sampling**), or a server sending asynchronous **notifications** to a client. These features enable more complex, bidirectional workflows and are fully supported by FastMCP.
|
| 115 |
+
|
| 116 |
+
## Next Steps
|
| 117 |
+
|
| 118 |
+
Now that you understand the core concepts of the Model Context Protocol, you're ready to start building. The best place to begin is our step-by-step tutorial.
|
| 119 |
+
|
| 120 |
+
[**Tutorial: How to Create an MCP Server in Python →**](/tutorials/create-mcp-server)
|
docs/tutorials/rest-api.mdx
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: "How to Connect an LLM to a REST API"
|
| 3 |
+
sidebarTitle: "Connect LLMs to REST APIs"
|
| 4 |
+
description: "A step-by-step guide to making any REST API with an OpenAPI spec available to LLMs using FastMCP."
|
| 5 |
+
icon: "plug"
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
You've built a powerful REST API, and now you want your LLM to be able to use it. Manually writing a wrapper function for every single endpoint is tedious, error-prone, and hard to maintain.
|
| 9 |
+
|
| 10 |
+
This is where **FastMCP** shines. If your API has an OpenAPI (or Swagger) specification, FastMCP can automatically convert your entire API into a fully-featured MCP server, making every endpoint available as a secure, typed tool for your AI model.
|
| 11 |
+
|
| 12 |
+
This guide will walk you through converting a public REST API into an MCP server in just a few lines of code.
|
| 13 |
+
|
| 14 |
+
<Tip>
|
| 15 |
+
Every code block in this tutorial is a complete, runnable example. You can copy and paste it into a file and run it, or paste it directly into a Python REPL like IPython to try it out.
|
| 16 |
+
</Tip>
|
| 17 |
+
|
| 18 |
+
### Prerequisites
|
| 19 |
+
|
| 20 |
+
Make sure you have FastMCP installed. If not, follow the [installation guide](/getting-started/installation).
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
pip install fastmcp
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
## Step 1: Choose a Target API
|
| 27 |
+
|
| 28 |
+
For this tutorial, we'll use the [JSONPlaceholder API](https://jsonplaceholder.typicode.com/), a free, fake online REST API for testing and prototyping. It's perfect because it's simple and has a public OpenAPI specification.
|
| 29 |
+
|
| 30 |
+
- **API Base URL:** `https://jsonplaceholder.typicode.com`
|
| 31 |
+
- **OpenAPI Spec URL:** We'll use a community-provided spec for it.
|
| 32 |
+
|
| 33 |
+
## Step 2: Create the MCP Server
|
| 34 |
+
|
| 35 |
+
Now for the magic. We'll use `FastMCP.from_openapi`. This method takes an `httpx.AsyncClient` configured for your API and its OpenAPI specification, and automatically converts **every endpoint** into a callable MCP `Tool`.
|
| 36 |
+
|
| 37 |
+
<Tip>
|
| 38 |
+
Learn more about working with OpenAPI specs in the [OpenAPI integration docs](/servers/openapi).
|
| 39 |
+
</Tip>
|
| 40 |
+
|
| 41 |
+
<Note>
|
| 42 |
+
For this tutorial, we'll use a simplified OpenAPI spec directly in the code. In a real project, you would typically load the spec from a URL or local file.
|
| 43 |
+
</Note>
|
| 44 |
+
|
| 45 |
+
Create a file named `api_server.py`:
|
| 46 |
+
|
| 47 |
+
```python api_server.py {31-35}
|
| 48 |
+
import httpx
|
| 49 |
+
from fastmcp import FastMCP
|
| 50 |
+
|
| 51 |
+
# Create an HTTP client for the target API
|
| 52 |
+
client = httpx.AsyncClient(base_url="https://jsonplaceholder.typicode.com")
|
| 53 |
+
|
| 54 |
+
# Define a simplified OpenAPI spec for JSONPlaceholder
|
| 55 |
+
openapi_spec = {
|
| 56 |
+
"openapi": "3.0.0",
|
| 57 |
+
"info": {"title": "JSONPlaceholder API", "version": "1.0"},
|
| 58 |
+
"paths": {
|
| 59 |
+
"/users": {
|
| 60 |
+
"get": {
|
| 61 |
+
"summary": "Get all users",
|
| 62 |
+
"operationId": "get_users",
|
| 63 |
+
"responses": {"200": {"description": "A list of users."}}
|
| 64 |
+
}
|
| 65 |
+
},
|
| 66 |
+
"/users/{id}": {
|
| 67 |
+
"get": {
|
| 68 |
+
"summary": "Get a user by ID",
|
| 69 |
+
"operationId": "get_user_by_id",
|
| 70 |
+
"parameters": [{"name": "id", "in": "path", "required": True, "schema": {"type": "integer"}}],
|
| 71 |
+
"responses": {"200": {"description": "A single user."}}
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
# Create the MCP server from the OpenAPI spec
|
| 78 |
+
mcp = FastMCP.from_openapi(
|
| 79 |
+
openapi_spec=openapi_spec,
|
| 80 |
+
client=client,
|
| 81 |
+
name="JSONPlaceholder MCP Server"
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
mcp.run(transport="streamable-http", port=8000)
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
And that's it! With just a few lines of code, you've created an MCP server that exposes the entire JSONPlaceholder API as a collection of tools.
|
| 89 |
+
|
| 90 |
+
## Step 3: Test the Generated Server
|
| 91 |
+
|
| 92 |
+
Let's verify that our new MCP server works. We can use the `fastmcp.Client` to connect to it and inspect its tools.
|
| 93 |
+
|
| 94 |
+
<Tip>
|
| 95 |
+
Learn more about the FastMCP client in the [client docs](/clients/client).
|
| 96 |
+
</Tip>
|
| 97 |
+
|
| 98 |
+
Create a separate file, `api_client.py`:
|
| 99 |
+
|
| 100 |
+
```python api_client.py {2, 6, 9, 16}
|
| 101 |
+
import asyncio
|
| 102 |
+
from fastmcp import Client
|
| 103 |
+
|
| 104 |
+
async def main():
|
| 105 |
+
# Connect to the MCP server we just created
|
| 106 |
+
async with Client("http://127.0.0.1:8000/mcp") as client:
|
| 107 |
+
|
| 108 |
+
# List the tools that were automatically generated
|
| 109 |
+
tools = await client.list_tools()
|
| 110 |
+
print("Generated Tools:")
|
| 111 |
+
for tool in tools:
|
| 112 |
+
print(f"- {tool.name}")
|
| 113 |
+
|
| 114 |
+
# Call one of the generated tools
|
| 115 |
+
print("\n\nCalling tool 'get_user_by_id'...")
|
| 116 |
+
user = await client.call_tool("get_user_by_id", {"id": 1})
|
| 117 |
+
print(f"Result:\n{user[0].text}")
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
asyncio.run(main())
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
First, run your server:
|
| 124 |
+
```bash
|
| 125 |
+
python api_server.py
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Then, in another terminal, run the client:
|
| 129 |
+
```bash
|
| 130 |
+
python api_client.py
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
You should see a list of generated tools (`get_users`, `get_user_by_id`) and the result of calling the `get_user_by_id` tool, which fetches data from the live JSONPlaceholder API.
|
| 134 |
+
|
| 135 |
+

|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
## Step 4: Customizing Route Maps
|
| 139 |
+
|
| 140 |
+
By default, FastMCP converts every API endpoint into an MCP `Tool`. This ensures maximum compatibility with contemporary LLM clients, many of which **only support the `tools` part of the MCP specification.**
|
| 141 |
+
|
| 142 |
+
However, for clients that support the full MCP spec, representing `GET` requests as `Resources` can be more semantically correct and efficient.
|
| 143 |
+
|
| 144 |
+
FastMCP allows users to customize this behavior using the concept of "route maps". A `RouteMap` is a mapping of an API route to an MCP type. FastMCP checks each API route against your custom maps in order. If a route matches a map, it's converted to the specified `mcp_type`. Any route that doesn't match your custom maps will fall back to the default behavior (becoming a `Tool`).
|
| 145 |
+
|
| 146 |
+
<Tip>
|
| 147 |
+
Learn more about route maps in the [OpenAPI integration docs](/servers/openapi#route-mapping).
|
| 148 |
+
</Tip>
|
| 149 |
+
|
| 150 |
+
Here’s how you can add custom route maps to turn `GET` requests into `Resources` and `ResourceTemplates` (if they have path parameters):
|
| 151 |
+
|
| 152 |
+
```python api_server_with_resources.py {3, 37-42}
|
| 153 |
+
import httpx
|
| 154 |
+
from fastmcp import FastMCP
|
| 155 |
+
from fastmcp.server.openapi import RouteMap, MCPType
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
# Create an HTTP client for the target API
|
| 159 |
+
client = httpx.AsyncClient(base_url="https://jsonplaceholder.typicode.com")
|
| 160 |
+
|
| 161 |
+
# Define a simplified OpenAPI spec for JSONPlaceholder
|
| 162 |
+
openapi_spec = {
|
| 163 |
+
"openapi": "3.0.0",
|
| 164 |
+
"info": {"title": "JSONPlaceholder API", "version": "1.0"},
|
| 165 |
+
"paths": {
|
| 166 |
+
"/users": {
|
| 167 |
+
"get": {
|
| 168 |
+
"summary": "Get all users",
|
| 169 |
+
"operationId": "get_users",
|
| 170 |
+
"responses": {"200": {"description": "A list of users."}}
|
| 171 |
+
}
|
| 172 |
+
},
|
| 173 |
+
"/users/{id}": {
|
| 174 |
+
"get": {
|
| 175 |
+
"summary": "Get a user by ID",
|
| 176 |
+
"operationId": "get_user_by_id",
|
| 177 |
+
"parameters": [{"name": "id", "in": "path", "required": True, "schema": {"type": "integer"}}],
|
| 178 |
+
"responses": {"200": {"description": "A single user."}}
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
# Create the MCP server with custom route mapping
|
| 185 |
+
mcp = FastMCP.from_openapi(
|
| 186 |
+
openapi_spec=openapi_spec,
|
| 187 |
+
client=client,
|
| 188 |
+
name="JSONPlaceholder MCP Server",
|
| 189 |
+
route_maps=[
|
| 190 |
+
# Map GET requests with path parameters (e.g., /users/{id}) to ResourceTemplate
|
| 191 |
+
RouteMap(methods=["GET"], pattern=r".*\{.*\}.*", mcp_type=MCPType.RESOURCE_TEMPLATE),
|
| 192 |
+
# Map all other GET requests to Resource
|
| 193 |
+
RouteMap(methods=["GET"], mcp_type=MCPType.RESOURCE),
|
| 194 |
+
]
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
if __name__ == "__main__":
|
| 198 |
+
mcp.run(transport="streamable-http", port=8000)
|
| 199 |
+
```
|
| 200 |
+
With this configuration:
|
| 201 |
+
- `GET /users/{id}` becomes a `ResourceTemplate`.
|
| 202 |
+
- `GET /users` becomes a `Resource`.
|
| 203 |
+
- Any `POST`, `PUT`, etc. endpoints would still become `Tools` by default.
|