This project contains 3 demos:
- This is a simple demo that offers a tool called
get_available_lockers_from_zone, with a parameterzonerequired. - The result of this demo is hardcoded for simplicity
- This is a demo which fetch the weather data from
api.weather.gov - There are 2 tools provided
get_alertsget_forecast - This API only works for querying weather of US locations
- This is a demo that offers a tool called
show_photodemonstrating an image response - The result of this demo is hardcoded for simplicity
The auth_token specified in profile will be included in the header of ALL API calls as:
Authorization: Bearer [auth_token]
you may use the AuthTokenAuthProvider class from auth/auth_provider.py as your AuthProvider like this:
from auth.auth_provider import AuthTokenAuthProvider
mcp = FastMCP(name=__name__, auth=AuthTokenAuthProvider([auth_token]))
profile ID will be included in the header, you may call the get_profile_id(ctx) method in the samples to get the profile ID if needed
streamable-http
@mcp.tool()
def addition(
a: Annotated[int, Field(description="first number to be added")],
b: Annotated[int, Field(description="second number to be added")],
ctx: Context
) -> dict:
"""Add 2 numbers"""
# profile_id = get_profile_id(ctx)
return a+b
Supported return types:
- str
- return the response directly as str for text responses
Return a dict for operations, the operation name should be specified in operation key
You should return an publicly accessible URL in image_url in order to show an image, format as below:
return {"operation": "show_image", "image_url": "https://your-domain.com/image.jpg"}
You may setup multiple MCP tool servers in a profile
[
{
"url":"http://localhost:8080/mcp/",
"auth_token":"abc"
},
{
"url":"http://localhost:8081/mcp/",
"auth_token":"abcd"
}
]
| Parameter | Type | Required | Description |
|---|---|---|---|
| url | str | true | the enpoint URL |
| auth_token | str | if api_key is not provided |
Auth Token, will be passed in Authorization header with the “Bearer” scheme |
| api_key | str | if auth_token is not provided |
API Key, will be passed in X-API-KEY header |
You may use tester/main.py to test your MCP server. Change the URL, Auth Token and profile ID here if needed.
transport = StreamableHttpTransport(
"http://localhost:8080/mcp/",
auth=BearerAuth("your auth token"),
headers={"M-PROFILE-ID": "your profile ID"},
)
python tester.main.py
Refer to cloudrun-sample/README.md