Skip to content

feat(mcp): add mcpserver qs with python sdk#1314

Open
sicoyle wants to merge 3 commits into
dapr:masterfrom
sicoyle:feat/mcp-crd
Open

feat(mcp): add mcpserver qs with python sdk#1314
sicoyle wants to merge 3 commits into
dapr:masterfrom
sicoyle:feat/mcp-crd

Conversation

@sicoyle
Copy link
Copy Markdown
Contributor

@sicoyle sicoyle commented May 20, 2026

Description

Summary

Adds AI/mcp/ — a quickstart demonstrating Dapr's MCPServer CRD and per-tool durable workflows across three MCP transports, with three middleware shapes that cover the canonical "observe / gate / transform" patterns.

Pure-Dapr SDK demo (no LLM, no agent framework). The agent-driven specific example is only in the dapr agents repo, linked from this quickstart's README.

What's in AI/mcp/

  • Three MCP transports behind identical calling code (only spec.endpoint differs in the YAML):

    Resource Transport Tools
    weather-mcp.yaml streamableHTTP http://localhost:8081/mcp get_weather, get_forecast
    local-tools-mcp.yaml stdio (spawned by daprd) current_time, echo
    notes-mcp.yaml sse http://localhost:8082/sse add_note, list_notes
  • Three middleware shapes — all configured on weather-mcp.yaml. The other two MCPServers stay clean for side-by-side comparison:

    Hook Type What it does
    rate_limit_workflow beforeCallTool (gate) Per-minute counter in state; rejects beyond MAX_CALLS_PER_MINUTE = 10 with a structured RuntimeError
    redact_pii_workflow beforeCallTool + mutate: true (transform) Strips emails/phones from string arguments before the upstream MCP server sees them
    audit_log_workflow afterCallTool (observe) Writes {tool, arguments, result, timestamp} to Redis under audit:<server>:<tool>:<ts>
  • uv workspace at AI/mcp/mcp-servers/ and python/sdk/ are workspace members with their own pyproject.toml; a single uv.lock. Mechanical markdown did not make sense given the setup, and we want are moving away from it in python sdk and dapr agents, so this PR includes the latest (non mechanical markdown) setup test-wise.

CI

New step in validate_python_quickstarts.yaml:

- name: Setup uv
  uses: astral-sh/setup-uv@v7
- name: Validate AI/mcp quickstart
  working-directory: ./AI/mcp
  run: uv run --group dev pytest -v tests/


## Issue reference

We strive to have all PRs being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #_[issue number]_

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

* [ ] The quickstart code compiles correctly
* [ ] You've tested new builds of the quickstart if you changed quickstart code
* [ ] You've updated the quickstart's README if necessary
* [ ] If you have changed the steps for a quickstart be sure that you have updated the automated validation accordingly. All of our quickstarts have annotations that allow them to be executed automatically as code. For more information see [mechanical-markdown](https://github.com/dapr/mechanical-markdown#readme). For user guide with examples see [Examples](https://github.com/dapr/mechanical-markdown/tree/main/examples#mechanical-markdown-by-example).

sicoyle added 2 commits May 20, 2026 14:13
…I tests

Signed-off-by: Samantha Coyle <sam@diagrid.io>
Signed-off-by: Samantha Coyle <sam@diagrid.io>
Copilot AI review requested due to automatic review settings May 20, 2026 19:30
@sicoyle sicoyle requested review from a team as code owners May 20, 2026 19:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new AI/mcp/ Python quickstart that demonstrates Dapr’s MCPServer resource with three MCP transports and workflow-based middleware hooks, plus an end-to-end pytest suite and CI validation via uv.

Changes:

  • Introduces an AI/mcp/ uv workspace containing MCP server implementations (streamableHTTP, stdio, SSE) and an SDK-driven workflow app.
  • Adds workflow middleware implementations for rate limiting, PII redaction (mutating hook), and audit logging, wired via resources/weather-mcp.yaml.
  • Adds pytest E2E coverage and a GitHub Actions step to execute the new quickstart tests.

Reviewed changes

Copilot reviewed 21 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
AI/mcp/tests/test_sdk_variant.py E2E test that runs dapr run and asserts expected output markers.
AI/mcp/tests/conftest.py Session fixtures to spawn MCP servers and check Dapr CLI availability.
AI/mcp/tests/_wait_utils.py Synchronous wait/poll helper used for readiness checks.
AI/mcp/tests/_process_utils.py Cross-platform process-group creation/termination helpers for cleanup.
AI/mcp/resources/weather-mcp.yaml MCPServer resource for weather + middleware hook configuration.
AI/mcp/resources/notes-mcp.yaml MCPServer resource for notes over SSE.
AI/mcp/resources/local-tools-mcp.yaml MCPServer resource for stdio local tools server.
AI/mcp/resources/statestore.yaml Redis state store component used by workflows/middleware.
AI/mcp/python/shared/middleware_workflows.py Workflow middleware implementations (rate limit, redact, audit) + registration helper.
AI/mcp/python/sdk/app.py SDK variant entrypoint (tool discovery + workflow scheduling + rate-limit demo).
AI/mcp/python/sdk/workflow.py Parent workflow that invokes one tool per MCPServer.
AI/mcp/python/sdk/README.md Run instructions and walkthrough for the SDK variant.
AI/mcp/python/sdk/pyproject.toml SDK variant Python dependencies.
AI/mcp/mcp-servers/weather_mcp_server.py Weather MCP server (streamableHTTP).
AI/mcp/mcp-servers/notes_sse_server.py Notes MCP server (SSE) implemented with Starlette/Uvicorn.
AI/mcp/mcp-servers/local_tools_server.py Local tools MCP server (stdio).
AI/mcp/mcp-servers/pyproject.toml MCP servers’ Python dependencies.
AI/mcp/pyproject.toml Workspace root project + dev dependencies for tests.
AI/mcp/uv.lock Locked dependency set for the uv workspace.
AI/mcp/dapr.yaml Dapr multi-app configuration for running the sdk variant.
AI/mcp/README.md Top-level quickstart documentation and how to run tests.
.github/workflows/validate_python_quickstarts.yaml Adds uv setup + executes AI/mcp pytest suite in CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AI/mcp/tests/test_sdk_variant.py
Comment thread AI/mcp/python/shared/middleware_workflows.py Outdated
Comment thread AI/mcp/python/shared/middleware_workflows.py
Comment thread AI/mcp/mcp-servers/notes_sse_server.py Outdated
Comment thread .github/workflows/validate_python_quickstarts.yaml
Signed-off-by: Samantha Coyle <sam@diagrid.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants