Skip to content

Commit 11a7d7a

Browse files
authored
Merge pull request #4 from madebygps/main
Adds all mcp examples, debugger config, Spanish readme
2 parents 247bdce + e9b5e60 commit 11a7d7a

15 files changed

+2980
-198
lines changed

.devcontainer/launch-inspector-codespace.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if [ -n "${CODESPACE_NAME:-}" ]; then
1111
echo " Inspector Proxy Address: $PROXY_URL"
1212
echo ""
1313

14-
ALLOWED_ORIGINS="$CODESPACE_URL" npx -y @modelcontextprotocol/inspector uv run main.py
14+
ALLOWED_ORIGINS="$CODESPACE_URL" npx -y @modelcontextprotocol/inspector
1515
else
1616
echo "🚀 Launching MCP Inspector..."
1717
npx -y @modelcontextprotocol/inspector

.env-sample

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# API Host Selection
2+
# Options: github, azure, ollama, openai
3+
API_HOST=github
4+
5+
# GitHub Models Configuration
6+
GITHUB_TOKEN=your_github_token_here
7+
GITHUB_MODEL=gpt-4o
8+
9+
# Azure OpenAI Configuration
10+
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
11+
AZURE_OPENAI_CHAT_DEPLOYMENT=your-deployment-name
12+
AZURE_OPENAI_VERSION=2024-02-15-preview
13+
14+
# Ollama Configuration
15+
OLLAMA_MODEL=llama3.1
16+
OLLAMA_ENDPOINT=http://localhost:11434/v1
17+
OLLAMA_API_KEY=ollama
18+
19+
# OpenAI Configuration (default if API_HOST not set)
20+
OPENAI_MODEL=gpt-4o-mini
21+
OPENAI_API_KEY=your_openai_api_key_here

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ __pycache__/
66
# C extensions
77
*.so
88

9+
.claude/
10+
.claude
11+
.claude*
12+
913
# Distribution / packaging
1014
.Python
1115
build/

.vscode/launch.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,29 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Attach to MCP Server",
5+
"name": "Launch MCP HTTP Server (Debug)",
6+
"type": "debugpy",
7+
"request": "launch",
8+
"program": "${workspaceFolder}/basic_mcp_http.py",
9+
"console": "integratedTerminal",
10+
"cwd": "${workspaceFolder}",
11+
"env": {
12+
"PYTHONUNBUFFERED": "1"
13+
}
14+
},
15+
{
16+
"name": "Launch MCP stdio Server (Debug)",
17+
"type": "debugpy",
18+
"request": "launch",
19+
"program": "${workspaceFolder}/basic_mcp_stdio.py",
20+
"console": "integratedTerminal",
21+
"cwd": "${workspaceFolder}",
22+
"env": {
23+
"PYTHONUNBUFFERED": "1"
24+
}
25+
},
26+
{
27+
"name": "Attach to MCP Server (stdio)",
628
"type": "debugpy",
729
"request": "attach",
830
"connect": {
@@ -15,6 +37,21 @@
1537
"remoteRoot": "${workspaceFolder}"
1638
}
1739
]
40+
},
41+
{
42+
"name": "Attach to MCP Server (HTTP)",
43+
"type": "debugpy",
44+
"request": "attach",
45+
"connect": {
46+
"host": "localhost",
47+
"port": 5679
48+
},
49+
"pathMappings": [
50+
{
51+
"localRoot": "${workspaceFolder}",
52+
"remoteRoot": "${workspaceFolder}"
53+
}
54+
]
1855
}
1956
]
2057
}

.vscode/mcp.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"cwd": "${workspaceFolder}",
77
"args": [
88
"run",
9-
"main.py"
9+
"basic_mcp_stdio.py"
1010
],
1111
"env": {
1212
"PYTHONUNBUFFERED": "1"
@@ -24,7 +24,7 @@
2424
"debugpy",
2525
"--listen",
2626
"0.0.0.0:5678",
27-
"main.py"
27+
"basic_mcp_stdio.py"
2828
],
2929
"env": {
3030
"PYTHONUNBUFFERED": "1"
@@ -33,6 +33,25 @@
3333
"expenses-mcp-http": {
3434
"type": "http",
3535
"url": "http://localhost:8000/mcp"
36+
},
37+
"expenses-mcp-http-debug": {
38+
"type": "stdio",
39+
"command": "uv",
40+
"cwd": "${workspaceFolder}",
41+
"args": [
42+
"run",
43+
"--",
44+
"python",
45+
"-m",
46+
"debugpy",
47+
"--listen",
48+
"0.0.0.0:5679",
49+
"--wait-for-client",
50+
"basic_mcp_http.py"
51+
],
52+
"env": {
53+
"PYTHONUNBUFFERED": "1"
54+
}
3655
}
3756
},
3857
"inputs": []

README.md

Lines changed: 103 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,154 @@
1-
# Python MCP Demos
1+
# Python MCP Demo
22

3-
This repository implements a **minimal MCP expense tracker**.
4-
5-
The Model Context Protocol (MCP) is an open standard that enables LLMs to connect to external data sources and tools.
3+
A demonstration project showcasing Model Context Protocol (MCP) implementations using FastMCP, with examples of stdio, HTTP transports, and integration with LangChain and Agent Framework.
64

75
## Table of Contents
86

9-
- [Getting Started](#getting-started)
10-
- [Environment Setup](#environment-setup)
11-
- [Run the MCP Server in VS Code](#run-the-mcp-server-in-vs-code)
12-
- [GitHub Copilot Chat Integration](#github-copilot-chat-integration)
13-
- [MCP Inspector](#mcp-inspector)
7+
- [Prerequisites](#prerequisites)
8+
- [Setup](#setup)
9+
- [Python Scripts](#python-scripts)
10+
- [MCP Server Configuration](#mcp-server-configuration)
1411
- [Debugging](#debugging)
15-
- [Debugging with VS Code and debugpy](#debugging-with-vs-code-and-debugpy)
16-
- [Testing with MCP Inspector](#testing-with-mcp-inspector)
17-
- [Contributing](#contributing)
18-
19-
20-
## Environment Setup
21-
22-
#### 1. GitHub Codespaces
23-
24-
1. Click the **Code** button
25-
2. Select the **Codespaces** tab
26-
3. Click **Create codespace on main**
27-
4. Wait for the environment to build (dependencies install automatically)
12+
- [License](#license)
2813

29-
#### 2. Local VS Code Dev Container
14+
## Prerequisites
3015

31-
**Requirements:** Docker + VS Code + Dev Containers extension
16+
- Python 3.13 or higher
17+
- [uv](https://docs.astral.sh/uv/)
18+
- API access to one of the following:
19+
- GitHub Models (GitHub token)
20+
- Azure OpenAI (Azure credentials)
21+
- Ollama (local installation)
22+
- OpenAI API (API key)
3223

33-
1. Open the repo in VS Code
34-
2. When prompted, select **Reopen in Container** (or run `Dev Containers: Reopen in Container` from the Command Palette)
35-
3. Wait for the container to build
24+
## Setup
3625

37-
#### 3. Local Machine Without a Dev Container
38-
39-
If you prefer a plain local environment, use **uv** for dependency management:
26+
1. Install dependencies using `uv`:
4027

4128
```bash
4229
uv sync
4330
```
4431

45-
## Using the Expenses MCP Server
32+
2. Copy `.env-sample` to `.env` and configure your environment variables:
4633

47-
### Run the MCP Server in VS Code with GitHub Copilot (Codespace/Local Dev Container/Local)
34+
```bash
35+
cp .env-sample .env
36+
```
4837

49-
1. Open `.vscode/mcp.json` in the editor
50-
1. Click the **Start** button (▶) above the server name `expenses-mcp`
51-
1. Confirm in the output panel that the server is running
52-
1. Open the GitHub Copilot Chat panel (bottom right, or via Command Palette: `GitHub Copilot: Focus Chat`)
53-
1. Click the **Tools** icon (wrench) at the bottom of the chat panel
54-
1. Ensure `expenses-mcp` is selected in the list of available tools
55-
1. Ask Copilot to invoke the tool:
56-
- "Use add_expense to record a $12 lunch today paid with visa"
38+
3. Edit `.env` with your API credentials. Choose one of the following providers by setting `API_HOST`:
39+
- `github` - GitHub Models (requires `GITHUB_TOKEN`)
40+
- `azure` - Azure OpenAI (requires Azure credentials)
41+
- `ollama` - Local Ollama instance
42+
- `openai` - OpenAI API (requires `OPENAI_API_KEY`)
5743

58-
### MCP Inspector
44+
## Python Scripts
5945

60-
The MCP Inspector is a browser-based visual testing and debugging tool for MCP servers. At the moment it does not work great with non STDIO MCP Servers when working inside of a Codespace.
46+
Run any script with: `uv run <script_name>`
6147

62-
#### Launch the MCP Inspector and connect to STDIO MCP Server in GitHub Codespace
48+
- **basic_mcp_http.py** - MCP server with HTTP transport on port 8000
49+
- **basic_mcp_stdio.py** - MCP server with stdio transport for VS Code integration
50+
- **langchainv1_mcp_http.py** - LangChain agent with MCP integration
51+
- **agentframework_mcp_learn.py** - Microsoft Agent Framework integration with MCP
6352

64-
1. Run the following command in the terminal:
65-
```bash
66-
.devcontainer/launch-inspector-codespace.sh
67-
```
68-
2. Note the **Inspector Proxy Address** and **Session Token** from the terminal output
53+
## MCP Server Configuration
6954

70-
3. In the **Ports** view, set port **6277** to **PUBLIC** visibility
55+
### Using with MCP Inspector
7156

72-
4. Access the Inspector UI and configure:
73-
- **Transport Type**: `STDIO`
74-
- **Command**: `uv`
75-
- **Arguments**: `run main.py`
76-
- Expand configuration area
77-
- **Inspector Proxy Address**: (from terminal output)
78-
- **Proxy Session Token**: (from terminal output)
57+
The [MCP Inspector](https://github.com/modelcontextprotocol/inspector) is a developer tool for testing and debugging MCP servers.
7958

80-
#### Launch the MCP Inspector and connect to STDIO MCP Server in VS Code and Dev Container
59+
> **Note:** While HTTP servers can technically work with port forwarding in Codespaces/Dev Containers, the setup for MCP Inspector and debugger attachment is not straightforward. For the best development experience with full debugging capabilities, we recommend running this project locally.
8160
82-
1. Run the following command in the terminal:
83-
```bash
84-
HOST=0.0.0.0 DANGEROUSLY_OMIT_AUTH=true npx -y @modelcontextprotocol/inspector
85-
```
86-
1. Open `http://localhost:6274` in your browser
87-
1. Access the Inspector UI and configure:
88-
- **Transport Type**: `STDIO`
89-
- **Command**: `uv`
90-
- **Arguments**: `run main.py`
61+
**For stdio servers:**
9162

92-
> **Note:** `HOST=0.0.0.0` is required in devcontainer environments to bind the Inspector to all network interfaces, allowing proper communication between the UI and proxy server. `DANGEROUSLY_OMIT_AUTH=true` disables authentication - only use in trusted development environments.
63+
```bash
64+
npx @modelcontextprotocol/inspector uv run basic_mcp_stdio.py
65+
```
66+
67+
**For HTTP servers:**
9368

94-
#### Launch the inspector locally:**
69+
1. Start the HTTP server:
70+
```bash
71+
uv run basic_mcp_http.py
72+
```
9573

96-
1. Run the following command in the terminal:
97-
```bash
98-
npx @modelcontextprotocol/inspector uv run main.py
99-
```
100-
2. The Inspector will automatically open in your browser at `http://localhost:6274`
74+
2. In another terminal, run the inspector:
75+
```bash
76+
npx @modelcontextprotocol/inspector http://localhost:8000/mcp
77+
```
10178

79+
The inspector provides a web interface to:
80+
- View available tools, resources, and prompts
81+
- Test tool invocations with custom parameters
82+
- Inspect server responses and errors
83+
- Debug server communication
10284

103-
---
85+
### Using with GitHub Copilot
10486

105-
## Debugging
87+
The `.vscode/mcp.json` file configures MCP servers for GitHub Copilot integration:
10688

107-
You can attach the VS Code debugger to the running MCP server to set breakpoints and inspect code execution.
89+
**Available Servers:**
10890

109-
### Debugging STDIO MCP server with GitHub Copilot in Codespace/Dev Container/locally
91+
- **expenses-mcp**: stdio transport server for production use
92+
- **expenses-mcp-debug**: stdio server with debugpy on port 5678
93+
- **expenses-mcp-http**: HTTP transport server at `http://localhost:8000/mcp`
94+
- **expenses-mcp-http-debug**: stdio server with debugpy on port 5679
11095

96+
**Switching Servers:**
11197

112-
1. Open `.vscode/mcp.json` in the editor
98+
Configure which server GitHub Copilot uses by selecting it in the Chat panel selecting the tools icon.
11399

114-
2. Start the **expenses-mcp-debug** server (instead of expenses-mcp)
100+
## Debugging
115101

116-
3. In VS Code, open the Run and Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
102+
### Debug Configurations
117103

118-
4. Select **"Attach to MCP Server"** from the dropdown and click the play button (or press F5)
104+
The `.vscode/launch.json` provides four debug configurations:
119105

120-
5. In GitHub Copilot Chat, make sure **expenses-mcp-debug** is selected in the tools menu
106+
#### Launch Configurations (Start server with debugging)
121107

122-
6. Set breakpoints in `main.py` and use the server from GitHub Copilot Chat. Breakpoints will be hit when tools are invoked.
108+
1. **Launch MCP HTTP Server (Debug)**
109+
- Directly starts `basic_mcp_http.py` with debugger attached
110+
- Best for: Standalone testing and LangChain script debugging
123111

124-
### Debugging HTTP MCP server with GitHub Copilot in Codespace/Dev Container/locally
112+
2. **Launch MCP stdio Server (Debug)**
113+
- Directly starts `basic_mcp_stdio.py` with debugger attached
114+
- Best for: Testing stdio communication
125115

126-
1. Run the HTTP MCP Server in the terminal with `uv run -- python -m debugpy --listen 0.0.0.0:5678 main_http.py`
116+
#### Attach Configurations (Attach to running server)
127117

128-
1. Open `.vscode/mcp.json` in the editor
118+
3. **Attach to MCP Server (stdio)** - Port 5678
119+
- Attaches to server started via `expenses-mcp-debug` in `mcp.json`
120+
- Best for: Debugging during GitHub Copilot Chat usage
129121

130-
1. Start the **expenses-mcp-debug** server (instead of expenses-mcp)
122+
4. **Attach to MCP Server (HTTP)** - Port 5679
123+
- Attaches to server started via `expenses-mcp-http-debug` in `mcp.json`
124+
- Best for: Debugging HTTP server during Copilot usage
131125

132-
1. In VS Code, open the Run and Debug panel (Ctrl+Shift+D / Cmd+Shift+D)
126+
### Debugging Workflow
133127

134-
1. Select **"Attach to MCP Server"** from the dropdown and click the play button (or press F5)
128+
#### Option 1: Launch and Debug (Standalone)
135129

136-
1. In GitHub Copilot Chat, make sure **expenses-mcp-debug** is selected in the tools menu
130+
Use this approach for debugging with MCP Inspector or LangChain scripts:
137131

138-
1. Set breakpoints in `main_http.py` and use the server from GitHub Copilot Chat. Breakpoints will be hit when tools are invoked.
132+
1. Set breakpoints in `basic_mcp_http.py` or `basic_mcp_stdio.py`
133+
2. Press `Cmd+Shift+D` to open Run and Debug
134+
3. Select "Launch MCP HTTP Server (Debug)" or "Launch MCP stdio Server (Debug)"
135+
4. Press `F5` or click the green play button
136+
5. Connect MCP Inspector or run your LangChain script to trigger breakpoints
137+
- For HTTP: `npx @modelcontextprotocol/inspector http://localhost:8000/mcp`
138+
- For stdio: `npx @modelcontextprotocol/inspector uv run basic_mcp_stdio.py` (start without debugger first)
139139

140-
---
140+
#### Option 2: Attach to Running Server (Copilot Integration)
141141

142+
1. Set breakpoints in your MCP server file
143+
1. Start the debug server via `mcp.json` configuration:
144+
- Select `expenses-mcp-debug` or `expenses-mcp-http-debug`
145+
1. Press `Cmd+Shift+D` to open Run and Debug
146+
1. Select appropriate "Attach to MCP Server" configuration
147+
1. Press `F5` to attach
148+
1. Select correct expense mcp server in GitHub Copilot Chat tools
149+
1. Use GitHub Copilot Chat to trigger the MCP tools
150+
1. Debugger pauses at breakpoints
142151

143-
## Contributing
152+
## License
144153

145-
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
154+
MIT

0 commit comments

Comments
 (0)