|
| 1 | +# MCP-Agent Server Starter |
| 2 | + |
| 3 | +Welcome! This project was generated by `mcp-agent init`. It demonstrates how to expose your mcp-agent application as an MCP server, making your agentic workflows available to any MCP client. |
| 4 | + |
| 5 | +## What's included |
| 6 | + |
| 7 | +- An `MCPApp` named `basic_agent_server` (see `main.py`). |
| 8 | +- A workflow class `BasicAgentWorkflow`: |
| 9 | + - Uses `Agent` to connect to `filesystem` and `fetch` MCP servers. |
| 10 | + - Demonstrates multi-turn conversations with an LLM (OpenAI). |
| 11 | + - Shows how to configure model preferences for specific requests. |
| 12 | +- A tool function decorated with `@app.tool`: |
| 13 | + - `grade_story(story: str, app_ctx?)` - Grades a student's short story using parallel agents (proofreader, fact checker, style enforcer) via `ParallelLLM`. |
| 14 | + - Returns the final result directly to the caller (no polling needed). |
| 15 | +- Server logs are forwarded to connected MCP clients as notifications. |
| 16 | + |
| 17 | +## What gets exposed as MCP tools |
| 18 | + |
| 19 | +When you run `main.py`, your MCP server exposes: |
| 20 | + |
| 21 | +- `workflows-list` - Lists available workflows and their parameter schemas |
| 22 | +- `workflows-BasicAgentWorkflow-run` - Executes the BasicAgentWorkflow with input |
| 23 | +- `workflows-get_status` - Get status for a running workflow by `run_id` |
| 24 | +- `workflows-cancel` - Cancel a running workflow |
| 25 | +- `grade_story` - Synchronous tool that grades a short story and returns the final result |
| 26 | + |
| 27 | +## Quick start |
| 28 | + |
| 29 | +1. Add your OpenAI API key to `mcp_agent.secrets.yaml` (or set `OPENAI_API_KEY` env var). |
| 30 | + |
| 31 | +NOTE: You can use another supported provider (e.g. Anthropic) instead, just be sure to set its API key in the `mcp_agent.secrets.yaml` (or set its env var) and import/use the relevant `AugmentedLLM` in `main.py`. |
| 32 | + |
| 33 | +2. Review `mcp_agent.config.yaml`: |
| 34 | + |
| 35 | + - Execution engine: `asyncio` |
| 36 | + - Logger settings |
| 37 | + - MCP servers: `filesystem`, `fetch` |
| 38 | + |
| 39 | +3. Install dependencies and run the server: |
| 40 | + |
| 41 | +```bash |
| 42 | +uv pip install -r requirements.txt |
| 43 | +uv run main.py |
| 44 | +``` |
| 45 | + |
| 46 | +The server will start and expose its tools over sse. You'll see: |
| 47 | + |
| 48 | +```bash |
| 49 | +Creating MCP server for basic_agent_server |
| 50 | +Registered workflows: |
| 51 | + - BasicAgentWorkflow |
| 52 | +MCP Server settings: ... |
| 53 | +``` |
| 54 | + |
| 55 | +4. Connect with an MCP client: |
| 56 | + |
| 57 | +You can connect to this server using any MCP client. For example, use [MCP Inspector](https://github.com/modelcontextprotocol/inspector) to explore and test: |
| 58 | + |
| 59 | +```bash |
| 60 | +npx @modelcontextprotocol/inspector --transport sse --server-url http://127.0.0.1:8000/sse |
| 61 | +``` |
| 62 | + |
| 63 | +This will launch the inspector UI where you can: |
| 64 | + |
| 65 | +- See all available tools (`grade_story`, `workflows-BasicAgentWorkflow-run`, etc.) |
| 66 | +- Test workflow execution |
| 67 | +- View request/response details |
| 68 | + |
| 69 | +5. Deploy as a remote MCP server: |
| 70 | + |
| 71 | +When you're ready to deploy, ensure the required API keys are set in `mcp_agent.secrets.yaml` and then run: |
| 72 | + |
| 73 | +```bash |
| 74 | +uv run mcp-agent login |
| 75 | +``` |
| 76 | + |
| 77 | +to authenticate to mcp-agent cloud. You will be redirected to the login page, create an mcp-agent cloud account through Google or Github. |
| 78 | + |
| 79 | +Set up your mcp-agent cloud API Key and copy & paste it into your terminal |
| 80 | + |
| 81 | +```bash |
| 82 | +INFO: Directing to MCP Agent Cloud API login... |
| 83 | +Please enter your API key 🔑: |
| 84 | +``` |
| 85 | + |
| 86 | +In your terminal, deploy the MCP app: |
| 87 | + |
| 88 | +```bash |
| 89 | +uv run mcp-agent deploy basic_agent_server |
| 90 | +``` |
| 91 | + |
| 92 | +You will then be prompted to specify the type of secret to save your OpenAI API key as. Select (1) deployment secret so that it is available to the deployed server. |
| 93 | + |
| 94 | +The `deploy` command will bundle the app files and deploy them, wrapping your app as a hosted MCP SSE server with a URL of the form: |
| 95 | +`https://<server_id>.deployments.mcp-agent.com`. |
| 96 | + |
| 97 | +Anything decorated with `@app.tool` (or `@app.async_tool`) runs as a Temporal workflow in the cloud. |
| 98 | + |
| 99 | +Since the mcp-agent app is exposed as an MCP server, it can be used in any MCP client just |
| 100 | +like any other MCP server. For example, you can inspect and test the server using MCP Inspector: |
| 101 | + |
| 102 | +```bash |
| 103 | +npx @modelcontextprotocol/inspector --transport sse --server-url https://<server_id>.deployments.mcp-agent.com/sse |
| 104 | +``` |
| 105 | + |
| 106 | +## Notes |
| 107 | + |
| 108 | +- `app_ctx` is the MCPApp Context (configuration, logger, upstream session, etc.). |
| 109 | +- Logging uses `app.logger` and is forwarded as notifications when connected to an MCP client. |
| 110 | +- Configuration is read from `mcp_agent.config.yaml` and `mcp_agent.secrets.yaml` (env vars supported). |
| 111 | +- The default model is configurable (see `openai.default_model` in config). |
| 112 | +- The server runs in `asyncio` mode and exposes tools via sse by default. |
| 113 | + |
| 114 | +## Key concepts demonstrated |
| 115 | + |
| 116 | +- **Creating workflows**: Use the `@app.workflow` decorator and `Workflow` base class to define reusable workflows. |
| 117 | +- **Defining tools**: Use `@app.tool` for synchronous tools that return results immediately. |
| 118 | +- **Using agents**: Create `Agent` instances with specific instructions and server access (filesystem, fetch, etc.). |
| 119 | +- **Parallel execution**: Use `ParallelLLM` to run multiple agents in parallel and aggregate their results. |
| 120 | +- **Multi-turn conversations**: LLMs maintain conversation context across multiple `generate_str()` calls. |
| 121 | +- **Model preferences**: Configure model selection via `RequestParams` and `ModelPreferences`. |
| 122 | +- **Server creation**: Use `create_mcp_server_for_app()` to wrap your MCPApp as an MCP server. |
| 123 | + |
| 124 | +## Next steps |
| 125 | + |
| 126 | +- Modify the `BasicAgentWorkflow` instructions or server list to fit your use case. |
| 127 | +- Add more tools with `@app.tool` or `@app.async_tool` as you grow the app. |
| 128 | +- Explore the `grade_story` tool to understand parallel agent execution. |
| 129 | +- Customize the agents used by `ParallelLLM` (proofreader, fact checker, style enforcer). |
| 130 | +- Read the docs and explore examples: |
| 131 | + - GitHub: https://github.com/lastmile-ai/mcp-agent |
| 132 | + - Docs: https://docs.mcp-agent.com/ |
| 133 | + - Discord: https://lmai.link/discord/mcp-agent |
| 134 | + |
| 135 | +## Further reading |
| 136 | + |
| 137 | +- Configuration reference and secrets management. |
| 138 | +- MCP servers (stdio, SSE, streamable_http, websockets) and timeouts. |
| 139 | +- Temporal workflows, activities, and logging/notifications when deployed. |
| 140 | +- Agents and LLMs: `AgentSpec`, prompts, and model defaults. |
| 141 | +- Using `@app.async_tool` for long-running workflows (returns workflow_id/run_id for polling). |
| 142 | + |
| 143 | +Happy building! |
0 commit comments