The Model Context Protocol (MCP) enables agents to interact with external tools, resources, and data sources. Fast Agent provides seamless integration with MCP servers.
Fast Agent comes with several built-in MCP servers you can use immediately:
fetch - Download and read web content
filesystem - Read and write local files
time - Get current time in different timezones
interpreter - Execute Python code with installed packages
brave-search - Search the web using Brave Search API
github - Interact with GitHub repositories
import asynciofrom fast_agent import FastAgentfast = FastAgent("MCP Demo")@fast.agent( name="researcher", instruction="You are a research assistant that can fetch web content and search.", servers=["fetch", "brave-search"], # Connect to multiple servers)async def main(): async with fast.run() as agent: await agent.researcher( "Research the latest developments in AI agents and summarize the key trends" )if __name__ == "__main__": asyncio.run(main())
EXTRA_TOOL_NAME = "a3_extra_tool"_EXTRA_TOOL_ADDED = Falsedef _extra_tool(note: str = "Tool list update confirmed") -> str: return f"Extra tool active: {note}"@app.tool( name="a3_trigger_tool_update", description="Add a new tool and emit a tool list changed notification.",)async def a3_trigger_tool_update(context: Context) -> str: global _EXTRA_TOOL_ADDED if not _EXTRA_TOOL_ADDED: context.fastmcp.add_tool( _extra_tool, name=EXTRA_TOOL_NAME, description="Extra tool registered after tool list update.", ) _EXTRA_TOOL_ADDED = True await context.request_context.session.send_tool_list_changed() return "Tool list change notification sent. Refresh tools to see updates."
@app.prompt("a3_daily_brief")def a3_daily_brief(project: str, focus: str = "status") -> str: """Prompt with arguments to exercise /prompt selection and argument collection.""" return ( "You are an A3-style briefing assistant. " f"Provide a {focus} update for project '{project}' with three bullets." )@app.prompt("a3_review")def a3_review(area: str = "UI") -> str: """Simple prompt for /prompt listing and selection UI.""" return ( "You are reviewing the A3 display style for the following area: " f"{area}. Provide a short critique and a next-step checklist." )
@mcp.tool()async def roll_new_character(campaign_name: str = "Adventure") -> str: """ Roll a new character for your campaign. Args: campaign_name: The name of the campaign Returns: Character details or status message """ class GameCharacter(BaseModel): character_name: str = Field(description="Name your character", min_length=2, max_length=30) character_class: str = Field( description="Choose your class", json_schema_extra={ "enum": ["warrior", "mage", "rogue", "ranger", "paladin", "bard"], }, ) strength: int = Field(description="Strength (3-18)", ge=3, le=18, default=10) result = await mcp.get_context().elicit( f"🎮 Create Character for {campaign_name}!", schema=GameCharacter ) match result: case AcceptedElicitation(data=data): response = f"🎭 {data.character_name} the {data.character_class.title()} joins {campaign_name}!\n" response += f"Stats: STR:{data.strength}" return response case DeclinedElicitation(): return f"Character creation for {campaign_name} was declined" case CancelledElicitation(): return f"Character creation for {campaign_name} was cancelled"
@fast.agent( name="custom_agent", instruction="You can use my custom tools.", servers=["custom-server"],)async def main(): async with fast.run() as agent: await agent.interactive()