Skip to content

Commit 06914b7

Browse files
add mcp server
1 parent 9e187bc commit 06914b7

File tree

6 files changed

+78
-29
lines changed

6 files changed

+78
-29
lines changed

.devcontainer/devcontainer.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/python
3+
{
4+
"name": "Python 3",
5+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6+
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
7+
"features": {
8+
"ghcr.io/jsburckhardt/devcontainer-features/uv:1": {},
9+
"ghcr.io/joedmck/devcontainer-features/cloudflared:1": {}
10+
}
11+
12+
// Features to add to the dev container. More info: https://containers.dev/features.
13+
// "features": {},
14+
15+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
16+
// "forwardPorts": [],
17+
18+
// Use 'postCreateCommand' to run commands after the container is created.
19+
// "postCreateCommand": "pip3 install --user -r requirements.txt",
20+
21+
// Configure tool-specific properties.
22+
// "customizations": {},
23+
24+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
25+
// "remoteUser": "root"
26+
}

.github/dependabot.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for more information:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
# https://containers.dev/guide/dependabot
6+
7+
version: 2
8+
updates:
9+
- package-ecosystem: "devcontainers"
10+
directory: "/"
11+
schedule:
12+
interval: weekly

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ requires-python = ">=3.11"
1010
dependencies = [
1111
"fastapi>=0.115.10",
1212
"loguru>=0.7.3",
13-
"mcp>=1.3.0",
13+
"mcp==1.0.0",
1414
"pydantic>=2.10.6",
1515
"uvicorn>=0.34.0",
1616
]

src/mcp_actions_adapter/lifespan.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import asyncio
2+
import os
3+
import shutil
4+
from fastapi import FastAPI
5+
from contextlib import asynccontextmanager
6+
from mcp_actions_adapter.config import config
7+
import mcp.client
8+
import mcp.client.stdio
9+
import mcp.client.session
10+
11+
server_session = None
12+
13+
def get_server():
14+
global server_session
15+
return server_session
16+
17+
@asynccontextmanager
18+
async def lifespan(app: FastAPI):
19+
global server_session
20+
server = config.mcpServers.popitem()[1]
21+
server.command = shutil.which(server.command) or server.command
22+
23+
server.env = os.environ.copy() | (server.env or {})
24+
25+
print(server)
26+
27+
async with mcp.client.stdio.stdio_client(server) as client:
28+
async with mcp.client.session.ClientSession(*client) as session:
29+
await asyncio.sleep(0.1)
30+
await session.initialize()
31+
server_session = session
32+
yield
33+

src/mcp_actions_adapter/main.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from fastapi import FastAPI
22
from mcp_actions_adapter.config import config
3+
from mcp_actions_adapter.lifespan import lifespan
34

45
app = FastAPI(
56
title="MCP Actions Adapter",
67
description="A simple adapter to convert a MCP server to a GPT actions compatible API",
78
servers=[{"url": config.url}],
9+
lifespan=lifespan,
810
)
911

uv.lock

+4-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)