http-mcp 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- http_mcp-0.0.1/.cursor/mcp.json +14 -0
- http_mcp-0.0.1/.cursor/rules/python-style.mdc +50 -0
- http_mcp-0.0.1/.envrc +11 -0
- http_mcp-0.0.1/.gemini/settings.json +15 -0
- http_mcp-0.0.1/.githooks/pre-push +1 -0
- http_mcp-0.0.1/.github/workflows/dev.yml +40 -0
- http_mcp-0.0.1/.gitignore +8 -0
- http_mcp-0.0.1/.python-version +1 -0
- http_mcp-0.0.1/.vscode/settings.json +22 -0
- http_mcp-0.0.1/AGENT.md +30 -0
- http_mcp-0.0.1/LICENSE +21 -0
- http_mcp-0.0.1/PKG-INFO +267 -0
- http_mcp-0.0.1/README.md +248 -0
- http_mcp-0.0.1/app/__init__.py +1 -0
- http_mcp-0.0.1/app/main.py +29 -0
- http_mcp-0.0.1/app/prompts.py +35 -0
- http_mcp-0.0.1/app/tools.py +108 -0
- http_mcp-0.0.1/assets/gemini_test.png +0 -0
- http_mcp-0.0.1/mypy.ini +9 -0
- http_mcp-0.0.1/pyproject.toml +52 -0
- http_mcp-0.0.1/ruff.toml +30 -0
- http_mcp-0.0.1/src/http_mcp/__init__.py +1 -0
- http_mcp-0.0.1/src/http_mcp/exceptions.py +53 -0
- http_mcp-0.0.1/src/http_mcp/http_transport.py +208 -0
- http_mcp-0.0.1/src/http_mcp/mcp_types/__init__.py +0 -0
- http_mcp-0.0.1/src/http_mcp/mcp_types/capabilities.py +11 -0
- http_mcp-0.0.1/src/http_mcp/mcp_types/content.py +8 -0
- http_mcp-0.0.1/src/http_mcp/mcp_types/messages.py +82 -0
- http_mcp-0.0.1/src/http_mcp/mcp_types/prompts.py +62 -0
- http_mcp-0.0.1/src/http_mcp/mcp_types/tools.py +48 -0
- http_mcp-0.0.1/src/http_mcp/prompts.py +68 -0
- http_mcp-0.0.1/src/http_mcp/py.typed +0 -0
- http_mcp-0.0.1/src/http_mcp/server.py +94 -0
- http_mcp-0.0.1/src/http_mcp/server_interface.py +53 -0
- http_mcp-0.0.1/src/http_mcp/stdio_transport.py +129 -0
- http_mcp-0.0.1/src/http_mcp/tools.py +98 -0
- http_mcp-0.0.1/src/http_mcp/transport_base.py +221 -0
- http_mcp-0.0.1/src/http_mcp/transport_types.py +19 -0
- http_mcp-0.0.1/tests/__init__.py +0 -0
- http_mcp-0.0.1/tests/models.py +34 -0
- http_mcp-0.0.1/tests/test_base_transport.py +123 -0
- http_mcp-0.0.1/tests/test_http_transport.py +110 -0
- http_mcp-0.0.1/tests/test_initialization.py +78 -0
- http_mcp-0.0.1/tests/test_prompts_methods.py +308 -0
- http_mcp-0.0.1/tests/test_server_with_context.py +70 -0
- http_mcp-0.0.1/tests/test_server_without_context.py +99 -0
- http_mcp-0.0.1/tests/test_studio_transport.py +148 -0
- http_mcp-0.0.1/tests/test_tools_methods.py +363 -0
- http_mcp-0.0.1/uv.lock +411 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
description:
|
|
3
|
+
globs:
|
|
4
|
+
alwaysApply: true
|
|
5
|
+
---
|
|
6
|
+
# Python Style Guide and Best Practices
|
|
7
|
+
|
|
8
|
+
## Type Hints
|
|
9
|
+
- All function parameters MUST have type hints
|
|
10
|
+
- All function return values MUST have type hints
|
|
11
|
+
- All class attributes MUST have type hints
|
|
12
|
+
- Use `collections.abc` for abstract base classes (Sequence, Mapping, Set, etc.)
|
|
13
|
+
- Use built-in types for simple type hints (str, int, bool, list, dict, etc.)
|
|
14
|
+
- Use `type | None` instead of `Optional[type]`
|
|
15
|
+
- Example:
|
|
16
|
+
```python
|
|
17
|
+
from collections.abc import Sequence
|
|
18
|
+
|
|
19
|
+
def process_data(items: Sequence[str], max_items: int | None = None) -> dict[str, int]:
|
|
20
|
+
...
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Functional Programming Paradigm
|
|
24
|
+
- Prefer pure functions over methods with side effects
|
|
25
|
+
- Use immutable data structures when possible, prefer tuples over lists
|
|
26
|
+
- Avoid modifying function arguments
|
|
27
|
+
- Use list/dict comprehensions instead of loops when possible
|
|
28
|
+
- Minimize global state and mutable variables
|
|
29
|
+
- Return new values instead of modifying existing ones
|
|
30
|
+
- Example:
|
|
31
|
+
```python
|
|
32
|
+
# Good - Pure function, immutable
|
|
33
|
+
def transform_data(data: list[int]) -> list[int]:
|
|
34
|
+
return [x * 2 for x in data if x > 0]
|
|
35
|
+
|
|
36
|
+
# Bad - Modifies input, has side effects
|
|
37
|
+
def transform_data(data: list[int]) -> None:
|
|
38
|
+
for i in range(len(data)):
|
|
39
|
+
data[i] *= 2
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Code Organization
|
|
43
|
+
- Keep functions small and focused on a single responsibility
|
|
44
|
+
- Use composition over inheritance
|
|
45
|
+
- Prefer dependency injection over global state
|
|
46
|
+
- Use descriptive variable names that reflect their purpose
|
|
47
|
+
|
|
48
|
+
## Testing
|
|
49
|
+
- Write unit tests for all pure functions
|
|
50
|
+
- Test edge cases and error conditions
|
http_mcp-0.0.1/.envrc
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"autoAccept": false,
|
|
3
|
+
"contextFileName": "AGENT.md",
|
|
4
|
+
"usageStatisticsEnabled": true,
|
|
5
|
+
"respectGitIgnore": true,
|
|
6
|
+
"mcpServers": {
|
|
7
|
+
"test": {
|
|
8
|
+
"httpUrl": "http://localhost:8000/mcp/",
|
|
9
|
+
"timeout": 5000,
|
|
10
|
+
"headers": {
|
|
11
|
+
"Authorization": "Bearer TEST_TOKEN"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
: && ruff check && mypy . && pytest --cov-report term-missing --cov=src --cov-fail-under=96 tests/ && mdformat . --wrap 80
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
permissions: read-all
|
|
2
|
+
concurrency:
|
|
3
|
+
cancel-in-progress: true
|
|
4
|
+
group: ${{ github.actor }}
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
test:
|
|
8
|
+
name: test
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- name: "Set up Python"
|
|
15
|
+
uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version-file: "pyproject.toml"
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v6
|
|
21
|
+
|
|
22
|
+
- name: Install the project
|
|
23
|
+
run: uv sync --locked --all-extras --dev
|
|
24
|
+
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: uv run pytest --cov=src --cov-fail-under=96 tests/
|
|
27
|
+
|
|
28
|
+
- name: Run mypy
|
|
29
|
+
run: uv run mypy . --config-file mypy.ini
|
|
30
|
+
|
|
31
|
+
- name: Run ruff
|
|
32
|
+
run: uv run ruff check .
|
|
33
|
+
|
|
34
|
+
- name: Run mdformat
|
|
35
|
+
run: uv run mdformat README.md --check --wrap 80
|
|
36
|
+
|
|
37
|
+
name: dev
|
|
38
|
+
on:
|
|
39
|
+
pull_request:
|
|
40
|
+
branches: [main]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"[python]": {
|
|
3
|
+
"editor.codeActionsOnSave": {
|
|
4
|
+
"source.fixAll": "explicit",
|
|
5
|
+
"source.organizeImports": "explicit"
|
|
6
|
+
},
|
|
7
|
+
"editor.rulers": [100],
|
|
8
|
+
"editor.tabSize": 4,
|
|
9
|
+
"editor.defaultFormatter": "charliermarsh.ruff"
|
|
10
|
+
},
|
|
11
|
+
"mypy-type-checker.cwd": "/",
|
|
12
|
+
"ruff.configurationPreference": "filesystemFirst",
|
|
13
|
+
"ruff.organizeImports": true,
|
|
14
|
+
"ruff.lineLength": 100,
|
|
15
|
+
"mypy-type-checker.args": ["--explicit-package-bases", "--config-file", "mypy.ini"],
|
|
16
|
+
"python.testing.pytestArgs": [
|
|
17
|
+
"test",
|
|
18
|
+
"-vv"
|
|
19
|
+
],
|
|
20
|
+
"python.testing.pytestEnabled": true,
|
|
21
|
+
"python.testing.unittestEnabled": false
|
|
22
|
+
}
|
http_mcp-0.0.1/AGENT.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Project
|
|
2
|
+
|
|
3
|
+
## Project description
|
|
4
|
+
|
|
5
|
+
This project is a base python project environment configuration using uv.
|
|
6
|
+
|
|
7
|
+
## General Instructions:
|
|
8
|
+
|
|
9
|
+
- When generating new python code, please follow the following coding style:
|
|
10
|
+
- Use 4 spaces for indentation.
|
|
11
|
+
- Use snake_case for variable names, functions, and parameters.
|
|
12
|
+
- Use PascalCase for class names.
|
|
13
|
+
- Prefer functional programming paradigms where appropriate.
|
|
14
|
+
- Use type hints for all functions, classes, and parameters as well as return
|
|
15
|
+
values.
|
|
16
|
+
- Use immutable data structures when possible, prefer tuples over lists.
|
|
17
|
+
- Avoid modifying function arguments.
|
|
18
|
+
- Use list/dict comprehensions instead of loops when possible.
|
|
19
|
+
- Minimize global state and mutable variables.
|
|
20
|
+
- Return new values instead of modifying existing ones.
|
|
21
|
+
- Keep functions small and focused on a single responsibility.
|
|
22
|
+
|
|
23
|
+
## Tools usage
|
|
24
|
+
|
|
25
|
+
- context7: when the user requests code examples, setup or configuration steps,
|
|
26
|
+
or library/API documentation, use this tool to generate the code.
|
|
27
|
+
- file_reader: when the user requests to read a file, use this tool to read the
|
|
28
|
+
file.
|
|
29
|
+
- safe_tool: when the user requests to run a command, use this tool to run the
|
|
30
|
+
command.
|
http_mcp-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yeison Liscano
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
http_mcp-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: http-mcp
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This is a HTTP implementation of the MCP protocol
|
|
5
|
+
Project-URL: Homepage, https://github.com/yeison-liscano/http_mcp
|
|
6
|
+
Project-URL: Issues, https://github.com/yeison-liscano/http_mcp/issues
|
|
7
|
+
Author-email: Yeison Liscano <yliscanoc@gmail.com>
|
|
8
|
+
Maintainer-email: Yeison Liscano <yliscanoc@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: automation,http,llm,mcp
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Requires-Python: <3.14,>=3.13
|
|
15
|
+
Requires-Dist: pydantic==2.10.5
|
|
16
|
+
Requires-Dist: starlette==0.47.2
|
|
17
|
+
Requires-Dist: uvicorn==0.35.0
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Simple HTTP MCP Server Implementation
|
|
21
|
+
|
|
22
|
+
This project provides a lightweight server implementation for the Model Context
|
|
23
|
+
Protocol (MCP) over HTTP. It allows you to expose Python functions as tools and
|
|
24
|
+
prompts that can be discovered and executed remotely via a JSON-RPC interface.
|
|
25
|
+
It is thought to be used with an Starlette or FastAPI application (see
|
|
26
|
+
[app/main.py](app/main.py)).
|
|
27
|
+
|
|
28
|
+
The following badge correspond to the server I use as example of of this
|
|
29
|
+
project. Found it in the [app/ folder](app/main.py).
|
|
30
|
+
|
|
31
|
+
<a href="https://glama.ai/mcp/servers/@yeison-liscano/http_mcp">
|
|
32
|
+
<img width="380" height="200" src="https://glama.ai/mcp/servers/@yeison-liscano/http_mcp/badge" alt="Simple HTTP Server MCP server" />
|
|
33
|
+
</a>
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- **MCP Protocol Compliant**: Implements the MCP specification for tool and
|
|
38
|
+
prompts discovery and execution. No support for notifications.
|
|
39
|
+
- **HTTP and STDIO Transport**: Uses HTTP (POST requests) or STDIO for
|
|
40
|
+
communication.
|
|
41
|
+
- **Async Support**: Built on `Starlette` or `FastAPI` for asynchronous request
|
|
42
|
+
handling.
|
|
43
|
+
- **Type-Safe**: Leverages `Pydantic` for robust data validation and
|
|
44
|
+
serialization.
|
|
45
|
+
- **Stateful Context**: Maintain state across tool calls using a context object.
|
|
46
|
+
- **Request Access**: Access the incoming request object from your tools.
|
|
47
|
+
|
|
48
|
+
## Tools
|
|
49
|
+
|
|
50
|
+
Tools are the functions that can be called by the client.
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
|
|
54
|
+
1. **Define the arguments and output for the tools:**
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
# app/tools/models.py
|
|
58
|
+
from pydantic import BaseModel, Field
|
|
59
|
+
|
|
60
|
+
class ToolArguments(BaseModel):
|
|
61
|
+
question: str = Field(description="The question to answer")
|
|
62
|
+
|
|
63
|
+
class ToolOutput(BaseModel):
|
|
64
|
+
answer: str = Field(description="The answer to the question")
|
|
65
|
+
|
|
66
|
+
# Note: the description on Field will be passed when listing the tools.
|
|
67
|
+
# Having a description is optional, but it's recommended to provide one.
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
2. **Define the tools:**
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
# app/tools/tools.py
|
|
74
|
+
import asyncio
|
|
75
|
+
from pydantic import BaseModel, Field
|
|
76
|
+
from http_mcp.tools import Tool, ToolArguments
|
|
77
|
+
|
|
78
|
+
from app.tools.models import ToolArguments, ToolOutput
|
|
79
|
+
|
|
80
|
+
def tool(args: ToolArguments[ToolArguments, None]) -> ToolOutput:
|
|
81
|
+
return ToolOutput(answer=f"Hello, {args.inputs.question}!") # access the inputs using args.inputs
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
# app/tools/__init__.py
|
|
87
|
+
|
|
88
|
+
from app.tools.models import ToolArguments, ToolOutput
|
|
89
|
+
from app.tools.tools import tool
|
|
90
|
+
from http_mcp.tools import Tool
|
|
91
|
+
|
|
92
|
+
TOOLS = (
|
|
93
|
+
Tool(
|
|
94
|
+
func=tool,
|
|
95
|
+
input=ToolArguments,
|
|
96
|
+
output=ToolOutput,
|
|
97
|
+
),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
__all__ = ["TOOLS"]
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
3. **Instantiate the server:**
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# app/main.py
|
|
108
|
+
from starlette.applications import Starlette
|
|
109
|
+
from http_mcp.server import MCPServer
|
|
110
|
+
from app.tools import TOOLS
|
|
111
|
+
|
|
112
|
+
mcp_server: MCPServer[None] = MCPServer(tools=TOOLS, name="test", version="1.0.0")
|
|
113
|
+
|
|
114
|
+
app = Starlette()
|
|
115
|
+
app.mount(
|
|
116
|
+
"/mcp",
|
|
117
|
+
mcp_server.app,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Stateful Context
|
|
123
|
+
|
|
124
|
+
This is the server context attribute, it could be seem as a global state for the
|
|
125
|
+
server.
|
|
126
|
+
|
|
127
|
+
You can use a context object to maintain state across tool calls. The context
|
|
128
|
+
object is passed to each tool call and can be used to store and retrieve data.
|
|
129
|
+
|
|
130
|
+
Example:
|
|
131
|
+
|
|
132
|
+
1. **Define a context class:**
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from dataclasses import dataclass, field
|
|
136
|
+
|
|
137
|
+
@dataclass
|
|
138
|
+
class Context:
|
|
139
|
+
called_tools: list[str] = field(default_factory=list)
|
|
140
|
+
|
|
141
|
+
def get_called_tools(self) -> list[str]:
|
|
142
|
+
return self.called_tools
|
|
143
|
+
|
|
144
|
+
def add_called_tool(self, tool_name: str) -> None:
|
|
145
|
+
self.called_tools.append(tool_name)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
1. **Instantiate the context and the server:**
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from app.tools import TOOLS, Context
|
|
152
|
+
from http_mcp.server import MCPServer
|
|
153
|
+
|
|
154
|
+
mcp_server: MCPServer[Context] = MCPServer(
|
|
155
|
+
tools=TOOLS,
|
|
156
|
+
name="test",
|
|
157
|
+
version="1.0.0",
|
|
158
|
+
context=Context(called_tools=[]),
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
1. **Access the context in your tools:**
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from pydantic import BaseModel, Field
|
|
166
|
+
from http_mcp.tools import ToolArguments
|
|
167
|
+
from app.tools import Context
|
|
168
|
+
|
|
169
|
+
class MyToolArguments(BaseModel):
|
|
170
|
+
question: str = Field(description="The question to answer")
|
|
171
|
+
|
|
172
|
+
class MyToolOutput(BaseModel):
|
|
173
|
+
answer: str = Field(description="The answer to the question")
|
|
174
|
+
|
|
175
|
+
async def my_tool(args: ToolArguments[MyToolArguments, Context]) -> MyToolOutput:
|
|
176
|
+
# Access the context
|
|
177
|
+
args.context.add_called_tool("my_tool")
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
return MyToolOutput(answer=f"Hello, {args.inputs.question}!")
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Stateless Context
|
|
184
|
+
|
|
185
|
+
You can access the incoming request object from your tools. The request object
|
|
186
|
+
is passed to each tool call and can be used to access headers, cookies, and
|
|
187
|
+
other request data (e.x request.state, request.scope).
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from pydantic import BaseModel, Field
|
|
191
|
+
from http_mcp.tools import ToolArguments
|
|
192
|
+
|
|
193
|
+
class MyToolArguments(BaseModel):
|
|
194
|
+
question: str = Field(description="The question to answer")
|
|
195
|
+
|
|
196
|
+
class MyToolOutput(BaseModel):
|
|
197
|
+
answer: str = Field(description="The answer to the question")
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
async def my_tool(args: ToolArguments[MyToolArguments, None]) -> MyToolOutput:
|
|
201
|
+
# Access the request
|
|
202
|
+
auth_header = args.request.headers.get("Authorization")
|
|
203
|
+
...
|
|
204
|
+
|
|
205
|
+
return MyToolOutput(answer=f"Hello, {args.inputs.question}!")
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Prompts
|
|
209
|
+
|
|
210
|
+
You could add interactive templates that are invoked by user choice.
|
|
211
|
+
|
|
212
|
+
1. **Define the arguments and output for the prompts:**
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from pydantic import BaseModel, Field
|
|
216
|
+
|
|
217
|
+
from http_mcp.mcp_types.content import TextContent
|
|
218
|
+
from http_mcp.mcp_types.prompts import PromptMessage
|
|
219
|
+
from http_mcp.prompts import Prompt
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
class GetAdvice(BaseModel):
|
|
223
|
+
topic: str = Field(description="The topic to get advice on")
|
|
224
|
+
include_actionable_steps: bool = Field(
|
|
225
|
+
description="Whether to include actionable steps in the advice", default=False
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def get_advice(args: GetAdvice) -> tuple[PromptMessage, ...]:
|
|
230
|
+
"""Get advice on a topic."""
|
|
231
|
+
template = """
|
|
232
|
+
You are a helpful assistant that can give advice on {topic}.
|
|
233
|
+
"""
|
|
234
|
+
if args.include_actionable_steps:
|
|
235
|
+
template += """
|
|
236
|
+
The advice should include actionable steps.
|
|
237
|
+
"""
|
|
238
|
+
return (
|
|
239
|
+
PromptMessage(role="user", content=TextContent(text=template.format(topic=args.topic))),
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
PROMPTS = (
|
|
244
|
+
Prompt(
|
|
245
|
+
func=get_advice,
|
|
246
|
+
arguments_type=GetAdvice,
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
2. **Instantiate the server:**
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from starlette.applications import Starlette
|
|
255
|
+
|
|
256
|
+
from app.prompts import PROMPTS
|
|
257
|
+
from http_mcp.server import MCPServer
|
|
258
|
+
|
|
259
|
+
app = Starlette()
|
|
260
|
+
mcp_server = MCPServer[None](tools=(), prompts=PROMPTS, name="test", version="1.0.0")
|
|
261
|
+
|
|
262
|
+
app.mount(
|
|
263
|
+
"/mcp",
|
|
264
|
+
mcp_server.app,
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
```
|