From 2416561b5c2f4a9a2f80fb077ebada120eaf3e5f Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 10 May 2025 15:52:10 -0400 Subject: [PATCH] Update composition.mdx --- docs/servers/composition.mdx | 82 ------------------------------------ 1 file changed, 82 deletions(-) diff --git a/docs/servers/composition.mdx b/docs/servers/composition.mdx index dbd881133..03affb34b 100644 --- a/docs/servers/composition.mdx +++ b/docs/servers/composition.mdx @@ -206,85 +206,3 @@ main_mcp.mount( Be cautious when choosing separators. Some MCP clients (like Claude Desktop) might have restrictions on characters allowed in tool names (e.g., `/` might not be supported). The defaults (`_` for names, `+` for URIs) are generally safe. - -## Example: Modular Application - -Here's a modular application structure using `import_server`: - - -```python main.py -from fastmcp import FastMCP -import asyncio -from modules.text_server import text_mcp -from modules.data_server import data_mcp -import random - -app = FastMCP(name="MainApplication") - -async def setup(): - # Import the utility servers - await app.import_server("text", text_mcp) - await app.import_server("data", data_mcp) - -@app.tool() -def process_and_analyze(record_id: int) -> str: - """Fetches a record and analyzes its string representation.""" - # Get record data - record = {"id": record_id, "value": random.random()} - - # Count words in the record string representation - word_count = len(str(record).split()) - - return ( - f"Record {record_id} has {word_count} words in its string " - f"representation." - ) - -if __name__ == "__main__": - asyncio.run(setup()) - app.run() -``` - -```python modules/text_server.py -from fastmcp import FastMCP - -text_mcp = FastMCP(name="TextUtilities") - -@text_mcp.tool() -def count_words(text: str) -> int: - """Counts words in a text.""" - return len(text.split()) - -@text_mcp.resource("resource://stopwords") -def get_stopwords() -> list[str]: - """Return a list of common stopwords.""" - return ["the", "a", "is", "in"] -``` - -```python modules/data_server.py -from fastmcp import FastMCP -import random -from typing import Dict - -data_mcp = FastMCP(name="DataAPI") - -@data_mcp.tool() -def fetch_record(record_id: int) -> Dict: - """Fetches a dummy data record.""" - return {"id": record_id, "value": random.random()} - -@data_mcp.resource("data://schema/{table}") -def get_table_schema(table: str) -> Dict: - """Provides a dummy schema for a table.""" - return {"table": table, "columns": ["id", "value"]} -``` - - -Running `main.py` starts a server that exposes these prefixed components: -- `text_count_words` -- `data_fetch_record` -- `process_and_analyze` (defined in main app) -- `text+resource://stopwords` -- `data+data://schema/{table}` (template) - -This pattern promotes code organization and reuse within your FastMCP projects. \ No newline at end of file