|
| 1 | +## 🧩 MCP in DSPy Code (User Guide) |
| 2 | + |
| 3 | +MCP (Model Context Protocol) lets DSPy Code talk to **external tools, APIs, files, and services** |
| 4 | +through MCP servers. You can think of it as **“plug-in power” for your DSPy programs**: |
| 5 | + |
| 6 | +- 📂 Read files and documents from your filesystem |
| 7 | +- 🐙 Pull issues and PRs from GitHub |
| 8 | +- 🗄️ Query databases (Postgres, etc.) |
| 9 | +- 🌐 Call web APIs or search engines |
| 10 | + |
| 11 | +DSPy Code acts as the **MCP client** and your chosen servers provide tools, resources, and prompts. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +### 🌐 Learn more MCP flows |
| 16 | + |
| 17 | +Share this page when you want to point people to **all the MCP resources in DSPy Code**: |
| 18 | + |
| 19 | +- 🐙 **GitHub tutorial (recommended)**: [MCP GitHub Triage Copilot](../tutorials/mcp-github-triage.md) |
| 20 | +- 📂 **Filesystem tutorial (experimental)**: [MCP Filesystem Assistant](../tutorials/mcp-filesystem-assistant.md) |
| 21 | +- 🧠 **Advanced guide**: [Advanced MCP Integration](../advanced/mcp-integration.md) |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +### 🧠 When should I use MCP? |
| 26 | + |
| 27 | +Use MCP when your DSPy program needs to: |
| 28 | + |
| 29 | +- Access data that **isn’t already in your Python process** |
| 30 | +- Call **external systems** (APIs, databases, search, Slack, etc.) |
| 31 | +- Build **richer workflows** than “prompt in, answer out” |
| 32 | + |
| 33 | +If you’re just generating local DSPy code from natural language, you don’t need MCP. |
| 34 | +As soon as you want your program to “reach out” to the world, MCP becomes very useful. |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +### 🚶 Quick CLI workflow |
| 39 | + |
| 40 | +From the interactive CLI: |
| 41 | + |
| 42 | +```bash |
| 43 | +→ /mcp-list # See configured MCP servers |
| 44 | +→ /mcp-connect <name> # Connect to a server |
| 45 | +→ /mcp-tools # Discover tools |
| 46 | +→ /mcp-resources # Discover resources |
| 47 | +→ /mcp-prompts # Discover prompts |
| 48 | +``` |
| 49 | + |
| 50 | +Example (GitHub server): |
| 51 | + |
| 52 | +```bash |
| 53 | +→ /mcp-connect github |
| 54 | +→ /mcp-tools github |
| 55 | +→ /mcp-call github listIssues {"owner": "your-org", "repo": "your-repo"} |
| 56 | +``` |
| 57 | + |
| 58 | +For filesystem, see the **experimental** tutorial for details and caveats. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### 📚 Recommended starting points |
| 63 | + |
| 64 | +- 🐙 **GitHub Triage Copilot (GitHub MCP)** *(recommended first)* |
| 65 | + Pull issues/PRs from a repo and get a daily triage summary. |
| 66 | + See: [MCP GitHub Triage Copilot](../tutorials/mcp-github-triage.md){ style="color: #2563eb; text-decoration: underline;" } |
| 67 | + |
| 68 | +- 📂 **Project Files Assistant (Filesystem MCP)** *(experimental / advanced)* |
| 69 | + Turn your local project into a browsable, explainable knowledge base. |
| 70 | + See: [MCP Filesystem Assistant](../tutorials/mcp-filesystem-assistant.md){ style="color: #2563eb; text-decoration: underline;" } |
| 71 | + |
| 72 | +For deeper details on transports, configuration, and advanced patterns, see: |
| 73 | + |
| 74 | +- 🔗 <a href="../advanced/mcp-integration/" style="color: #2563eb; text-decoration: underline;">Advanced MCP Integration</a> |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +### ✅ Mental model recap |
| 79 | + |
| 80 | +- **DSPy Code** = MCP client (you control it from the CLI) |
| 81 | +- **MCP servers** = external capabilities (filesystem, GitHub, DB, web, etc.) |
| 82 | +- **DSPy modules** = the logic that **combines** model reasoning + MCP data/tools |
| 83 | + |
| 84 | +Once you’ve connected one or more MCP servers, you can simply **describe the workflow you want** |
| 85 | +in natural language and let DSPy Code generate DSPy programs that call those tools behind the scenes. |
| 86 | + |
| 87 | + |
0 commit comments