Creating a FlashMCP Server
A FlashMCP server is a collection of tools, resources, and other MCP components. To create a server, start by instantiating theFlashMCP class.
Create a new file called my_server.py and add the following code:
my_server.py
Adding a Tool
To add a tool that returns a simple greeting, write a function and decorate it with@mcp.tool to register it with the server:
my_server.py
Testing the Server
To test the server, create a FlashMCP client and point it at the server object.my_server.py
- Clients are asynchronous, so we need to use
asyncio.runto run the client. - We must enter a client context (
async with client:) before using the client. You can make multiple client calls within the same context.
Running the server
In order to run the server with Python, we need to add arun statement to the __main__ block of the server file.
my_server.py
python my_server.py, using the default stdio transport, which is the standard way to expose an MCP server to a client.
Interacting with the Python server
Now that the server can be executed withpython my_server.py, we can interact with it like any other MCP server.
In a new file, create a client and point it at the server file:
my_client.py
Using the FlashMCP CLI
To have FlashMCP run the server for us, we can use theFlashMCP run command. This will start the server and keep it running until it is stopped. By default, it will use the stdio transport, which is a simple text-based protocol for interacting with the server.
__main__ block in the server file, and will ignore it if it is present. Instead, it looks for the server object provided in the CLI command (here, mcp). If no server object is provided, FlashMCP run will automatically search for servers called “mcp”, “app”, or “server” in the file.