Publish FastMCP 4 (alpha) docs to gofastmcp.com (#4624)

This commit is contained in:
Jeremiah Lowin 2026-07-23 21:21:01 -04:00 committed by GitHub
commit 8cf4506aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
846 changed files with 86684 additions and 22013 deletions

View file

@ -3,16 +3,17 @@ This example demonstrates how to set up and use an in-memory FastMCP proxy.
It illustrates the pattern:
1. Create an original FastMCP server with some tools.
2. Create a proxy FastMCP server using ``FastMCP.as_proxy(original_server)``.
2. Create a proxy FastMCP server using ``create_proxy(original_server)``.
3. Use another Client to connect to the proxy server (in-memory) and interact with the original server's tools through the proxy.
"""
import asyncio
from mcp.types import TextContent
from mcp_types import TextContent
from fastmcp import FastMCP
from fastmcp.client import Client
from fastmcp.server import create_proxy
class EchoService:
@ -37,10 +38,8 @@ async def main():
# 2. Proxy Server Creation
print("\nStep 2: Creating the Proxy Server (InMemoryProxy)...")
print(
f" (Using FastMCP.as_proxy to wrap '{original_server.name}' directly)"
)
proxy_server = FastMCP.as_proxy(original_server, name="InMemoryProxy")
print(f" (Using create_proxy to wrap '{original_server.name}' directly)")
proxy_server = create_proxy(original_server, name="InMemoryProxy")
print(
f" -> Proxy Server '{proxy_server.name}' created, proxying '{original_server.name}'."
)
@ -65,8 +64,10 @@ async def main():
print(f"\n Calling 'echo' tool via proxy with message: '{message_to_echo}'")
try:
result = await final_client.call_tool("echo", {"message": message_to_echo})
if result and isinstance(result[0], TextContent):
print(f" Result from proxied 'echo' call: '{result[0].text}'")
if result.content and isinstance(result.content[0], TextContent):
print(
f" Result from proxied 'echo' call: '{result.content[0].text}'"
)
else:
print(
f" Error: Unexpected result format from proxied 'echo' call: {result}"