Skip to content

Commit a252a76

Browse files
authored
Initial commit
0 parents  commit a252a76

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

Containerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM registry.redhat.io/ubi9/python-311
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt ./
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY mcp_server.py ./
9+
10+
CMD ["python", "mcp_server.py"]

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# mcp-server template
2+
3+
MCP (ModelContextProvider) server template
4+
5+
---
6+
7+
## Building locally
8+
9+
To build the container image locally using Podman, run:
10+
11+
```sh
12+
podman build -t mcp-server-template:latest .
13+
```
14+
15+
This will create a local image named `mcp-server-template:latest` that you can use to run the server.
16+
17+
## Running with Podman or Docker
18+
19+
Example configuration for running with Podman:
20+
21+
```json
22+
{
23+
"mcpServers": {
24+
"mcp-server": {
25+
"command": "podman",
26+
"args": [
27+
"run",
28+
"-i",
29+
"--rm",
30+
"-e", "API_BASE_URL",
31+
"-e", "API_KEY",
32+
"-e", "MCP_TRANSPORT",
33+
"localhost/mcp-server-template:latest"
34+
],
35+
"env": {
36+
"API_BASE_URL": "https://api.example.com",
37+
"API_KEY": "REDACTED",
38+
"MCP_TRANSPORT": "stdio"
39+
}
40+
}
41+
}
42+
}
43+
```

mcp_server.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
from typing import Any
3+
4+
import httpx
5+
from mcp.server.fastmcp import FastMCP
6+
7+
mcp = FastMCP("mcp-server")
8+
9+
API_BASE_URL = os.environ["API_BASE_URL"]
10+
11+
12+
async def make_request(
13+
url: str, method: str = "GET", data: dict[str, Any] = None
14+
) -> dict[str, Any] | None:
15+
api_key = os.environ.get("API_KEY")
16+
if api_key:
17+
headers = {
18+
"Authorization": f"Bearer {api_key}",
19+
"Accept": "application/json",
20+
}
21+
else:
22+
headers = {}
23+
24+
async with httpx.AsyncClient() as client:
25+
if method.upper() == "GET":
26+
response = await client.request(method, url, headers=headers, params=data)
27+
else:
28+
response = await client.request(method, url, headers=headers, json=data)
29+
response.raise_for_status()
30+
return response.json()
31+
32+
33+
@mcp.tool()
34+
async def example():
35+
"""Simple example tool to demonstrate MCP server functionality."""
36+
url = f"{API_BASE_URL}/example"
37+
response = await make_request(url)
38+
return response
39+
40+
41+
if __name__ == "__main__":
42+
mcp.run(transport=os.environ.get("MCP_TRANSPORT", "stdio"))

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
httpx
2+
fastmcp

0 commit comments

Comments
 (0)