Menu

Post image 1
Post image 2
1 / 2
0

Build an MCP Server in Python in 15 Minutes

DEV Community·The Daily Agent·28 days ago
#PsZexsTj
#connecting#python#mcp#tutorial#tool#server
Reading 0:00
15s threshold

Drop this into a file and run it: from mcp.server.fastmcp import FastMCP import httpx mcp = FastMCP ( " mini-tools " ) @mcp.tool () def read_file ( path : str ) -> str : """ Read the contents of a file. """ with open ( path ) as f : return f . read () @mcp.tool () async def fetch_url ( url : str ) -> str : """ Fetch a URL and return the response text. """ async with httpx . AsyncClient () as client : resp = await client . get ( url ) return resp . text if __name__ == " __main__ " : mcp . run () Enter fullscreen mode Exit fullscreen mode Save as server.py , install the one dependency, and start it: pip install mcp httpx python server.py Enter fullscreen mode Exit fullscreen mode You now have an MCP server that gives any AI agent the ability to read files and fetch web pages. In 13 lines of code. How the FastMCP API works The mcp package ships two APIs. The older one uses @app.list_tools() and @app.call_tool() decorators that receive raw JSON.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More