FlashMCP
class.
Create a new file called my_server.py
and add the following code:
@mcp.tool
to register it with the server:
asyncio.run
to run the client.async with client:
) before using the client. You can make multiple client calls within the same context.run
statement to the __main__
block of the server file.
python my_server.py
, using the default stdio
transport, which is the standard way to expose an MCP server to a client.
if __name__ == "__main__":
block?Within the FlashMCP ecosystem, this line may be unnecessary. However, including it ensures that your FlashMCP server runs for all users and clients in a consistent way and is therefore recommended as best practice.python 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:
FlashMCP 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.
python my_server.py
by default. This executes the __main__
block of the server file. There are other ways to run the server, which are described in the server configuration guide.