Quick start
Install the Python SDK and serve your first tool
This page adds the SDK to a Python project. To start from a ready-made project instead, run nitrostack-py init my-server --template python-starter, which writes the project files and installs dependencies.
Install the package
Python 3.10 or newer is required. One package installs both the SDK and the nitrostack-py command.
pip install nitrostack
nitrostack-py --helpWrite a tool
A tool is a method on a controller class, marked with @tool. Its input is a Pydantic model.
from pydantic import BaseModel, Field
from nitrostack import tool, injectable, module, ExecutionContext
class AddInput(BaseModel):
a: float = Field(description="First number")
b: float = Field(description="Second number")
@injectable(deps=[])
class CalculatorController:
@tool(name="add", description="Add two numbers together", input_schema=AddInput)
async def add(self, input: AddInput, context: ExecutionContext) -> float:
context.logger.info(f"Adding {input.a} and {input.b}")
return input.a + input.b
@module(name="calculator", controllers=[CalculatorController])
class CalculatorModule:
passCreate the root module and start the server
The root module imports your feature modules. The factory builds the application from it.
import asyncio
from nitrostack import module, McpApplicationFactory
from calculator import CalculatorModule
@module(name="app", imports=[CalculatorModule])
class AppModule:
pass
async def main():
app = await McpApplicationFactory.create(AppModule)
await app.start()
if __name__ == "__main__":
asyncio.run(main())Run it with nitrostack-py dev, which hot-reloads main.py. The transport defaults to stdio unless you set MCP_TRANSPORT_TYPE. To try it over HTTP with MCP Inspector, run MCP_TRANSPORT_TYPE=http MCP_STATELESS=true nitrostack-py dev --port 3000 and connect to http://localhost:3000/mcp, with no trailing slash.
