Skip to content

Commit d04d17c

Browse files
authored
Merge branch 'main' into main
2 parents 7e02ddd + f3cd20c commit d04d17c

File tree

103 files changed

+1104
-2308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1104
-2308
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Applied 120 line-length rule to all files: https://github.com/modelcontextprotocol/python-sdk/pull/856
2+
543961968c0634e93d919d509cce23a1d6a56c21

.github/ISSUE_TEMPLATE/bug.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: 🐛 MCP Python SDK Bug
2+
description: Report a bug or unexpected behavior in the MCP Python SDK
3+
labels: ["need confirmation"]
4+
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: Thank you for contributing to the MCP Python SDK! ✊
9+
10+
- type: checkboxes
11+
id: checks
12+
attributes:
13+
label: Initial Checks
14+
description: Just making sure you're using the latest version of MCP Python SDK.
15+
options:
16+
- label: I confirm that I'm using the latest version of MCP Python SDK
17+
required: true
18+
- label: I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
19+
required: true
20+
21+
- type: textarea
22+
id: description
23+
attributes:
24+
label: Description
25+
description: |
26+
Please explain what you're seeing and what you would expect to see.
27+
28+
Please provide as much detail as possible to make understanding and solving your problem as quick as possible. 🙏
29+
validations:
30+
required: true
31+
32+
- type: textarea
33+
id: example
34+
attributes:
35+
label: Example Code
36+
description: >
37+
If applicable, please add a self-contained,
38+
[minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example)
39+
demonstrating the bug.
40+
41+
placeholder: |
42+
from mcp.server.fastmcp import FastMCP
43+
44+
...
45+
render: Python
46+
47+
- type: textarea
48+
id: version
49+
attributes:
50+
label: Python & MCP Python SDK
51+
description: |
52+
Which version of Python and MCP Python SDK are you using?
53+
render: Text
54+
validations:
55+
required: true

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 🚀 MCP Python SDK Feature Request
2+
description: "Suggest a new feature for the MCP Python SDK"
3+
labels: ["feature request"]
4+
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: Thank you for contributing to the MCP Python SDK! ✊
9+
10+
- type: textarea
11+
id: description
12+
attributes:
13+
label: Description
14+
description: |
15+
Please give as much detail as possible about the feature you would like to suggest. 🙏
16+
17+
You might like to add:
18+
* A demo of how code might look when using the feature
19+
* Your use case(s) for the feature
20+
* Reference to other projects that have a similar feature
21+
validations:
22+
required: true
23+
24+
- type: textarea
25+
id: references
26+
attributes:
27+
label: References
28+
description: |
29+
Please add any links or references that might help us understand your feature request better. 📚

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/question.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ❓ MCP Python SDK Question
2+
description: "Ask a question about the MCP Python SDK"
3+
labels: ["question"]
4+
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: Thank you for reaching out to the MCP Python SDK community! We're here to help! 🤝
9+
10+
- type: textarea
11+
id: question
12+
attributes:
13+
label: Question
14+
description: |
15+
Please provide as much detail as possible about your question. 🙏
16+
17+
You might like to include:
18+
* Code snippets showing what you've tried
19+
* Error messages you're encountering (if any)
20+
* Expected vs actual behavior
21+
* Your use case and what you're trying to achieve
22+
validations:
23+
required: true
24+
25+
- type: textarea
26+
id: context
27+
attributes:
28+
label: Additional Context
29+
description: |
30+
Please provide any additional context that might help us better understand your question, such as:
31+
* Your MCP Python SDK version
32+
* Your Python version
33+
* Relevant configuration or environment details 📝

.github/workflows/check-lock.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/shared.yml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,28 @@ on:
44
workflow_call:
55

66
jobs:
7-
format:
7+
pre-commit:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v4
1111

12-
- name: Install uv
13-
uses: astral-sh/setup-uv@v3
12+
- uses: astral-sh/setup-uv@v5
1413
with:
1514
enable-cache: true
1615
version: 0.7.2
1716

18-
- name: Install the project
19-
run: uv sync --frozen --all-extras --dev --python 3.12
20-
21-
- name: Run ruff format check
22-
run: uv run --no-sync ruff check .
23-
24-
typecheck:
25-
runs-on: ubuntu-latest
26-
steps:
27-
- uses: actions/checkout@v4
17+
- name: Install dependencies
18+
run: uv sync --frozen --all-extras --python 3.10
2819

29-
- name: Install uv
30-
uses: astral-sh/setup-uv@v3
20+
- uses: pre-commit/[email protected]
3121
with:
32-
enable-cache: true
33-
version: 0.7.2
34-
35-
- name: Install the project
36-
run: uv sync --frozen --all-extras --dev --python 3.12
37-
38-
- name: Run pyright
39-
run: uv run --no-sync pyright
22+
extra_args: --all-files --verbose
23+
env:
24+
SKIP: no-commit-to-branch
4025

4126
test:
4227
runs-on: ${{ matrix.os }}
28+
timeout-minutes: 10
4329
strategy:
4430
matrix:
4531
python-version: ["3.10", "3.11", "3.12", "3.13"]
@@ -55,7 +41,7 @@ jobs:
5541
version: 0.7.2
5642

5743
- name: Install the project
58-
run: uv sync --frozen --all-extras --dev --python ${{ matrix.python-version }}
44+
run: uv sync --frozen --all-extras --python ${{ matrix.python-version }}
5945

6046
- name: Run pytest
6147
run: uv run --no-sync pytest

examples/fastmcp/memory.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,14 @@
4747

4848
DB_DSN = "postgresql://postgres:postgres@localhost:54320/memory_db"
4949
# reset memory with rm ~/.fastmcp/{USER}/memory/*
50-
PROFILE_DIR = (
51-
Path.home() / ".fastmcp" / os.environ.get("USER", "anon") / "memory"
52-
).resolve()
50+
PROFILE_DIR = (Path.home() / ".fastmcp" / os.environ.get("USER", "anon") / "memory").resolve()
5351
PROFILE_DIR.mkdir(parents=True, exist_ok=True)
5452

5553

5654
def cosine_similarity(a: list[float], b: list[float]) -> float:
5755
a_array = np.array(a, dtype=np.float64)
5856
b_array = np.array(b, dtype=np.float64)
59-
return np.dot(a_array, b_array) / (
60-
np.linalg.norm(a_array) * np.linalg.norm(b_array)
61-
)
57+
return np.dot(a_array, b_array) / (np.linalg.norm(a_array) * np.linalg.norm(b_array))
6258

6359

6460
async def do_ai[T](
@@ -97,9 +93,7 @@ class MemoryNode(BaseModel):
9793
summary: str = ""
9894
importance: float = 1.0
9995
access_count: int = 0
100-
timestamp: float = Field(
101-
default_factory=lambda: datetime.now(timezone.utc).timestamp()
102-
)
96+
timestamp: float = Field(default_factory=lambda: datetime.now(timezone.utc).timestamp())
10397
embedding: list[float]
10498

10599
@classmethod
@@ -152,9 +146,7 @@ async def merge_with(self, other: Self, deps: Deps):
152146
self.importance += other.importance
153147
self.access_count += other.access_count
154148
self.embedding = [(a + b) / 2 for a, b in zip(self.embedding, other.embedding)]
155-
self.summary = await do_ai(
156-
self.content, "Summarize the following text concisely.", str, deps
157-
)
149+
self.summary = await do_ai(self.content, "Summarize the following text concisely.", str, deps)
158150
await self.save(deps)
159151
# Delete the merged node from the database
160152
if other.id is not None:
@@ -221,9 +213,7 @@ async def find_similar_memories(embedding: list[float], deps: Deps) -> list[Memo
221213

222214
async def update_importance(user_embedding: list[float], deps: Deps):
223215
async with deps.pool.acquire() as conn:
224-
rows = await conn.fetch(
225-
"SELECT id, importance, access_count, embedding FROM memories"
226-
)
216+
rows = await conn.fetch("SELECT id, importance, access_count, embedding FROM memories")
227217
for row in rows:
228218
memory_embedding = row["embedding"]
229219
similarity = cosine_similarity(user_embedding, memory_embedding)
@@ -273,25 +263,19 @@ async def display_memory_tree(deps: Deps) -> str:
273263
)
274264
result = ""
275265
for row in rows:
276-
effective_importance = row["importance"] * (
277-
1 + math.log(row["access_count"] + 1)
278-
)
266+
effective_importance = row["importance"] * (1 + math.log(row["access_count"] + 1))
279267
summary = row["summary"] or row["content"]
280268
result += f"- {summary} (Importance: {effective_importance:.2f})\n"
281269
return result
282270

283271

284272
@mcp.tool()
285273
async def remember(
286-
contents: list[str] = Field(
287-
description="List of observations or memories to store"
288-
),
274+
contents: list[str] = Field(description="List of observations or memories to store"),
289275
):
290276
deps = Deps(openai=AsyncOpenAI(), pool=await get_db_pool())
291277
try:
292-
return "\n".join(
293-
await asyncio.gather(*[add_memory(content, deps) for content in contents])
294-
)
278+
return "\n".join(await asyncio.gather(*[add_memory(content, deps) for content in contents]))
295279
finally:
296280
await deps.pool.close()
297281

@@ -305,9 +289,7 @@ async def read_profile() -> str:
305289

306290

307291
async def initialize_database():
308-
pool = await asyncpg.create_pool(
309-
"postgresql://postgres:postgres@localhost:54320/postgres"
310-
)
292+
pool = await asyncpg.create_pool("postgresql://postgres:postgres@localhost:54320/postgres")
311293
try:
312294
async with pool.acquire() as conn:
313295
await conn.execute("""

examples/fastmcp/text_me.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828

2929

3030
class SurgeSettings(BaseSettings):
31-
model_config: SettingsConfigDict = SettingsConfigDict(
32-
env_prefix="SURGE_", env_file=".env"
33-
)
31+
model_config: SettingsConfigDict = SettingsConfigDict(env_prefix="SURGE_", env_file=".env")
3432

3533
api_key: str
3634
account_id: str
37-
my_phone_number: Annotated[
38-
str, BeforeValidator(lambda v: "+" + v if not v.startswith("+") else v)
39-
]
35+
my_phone_number: Annotated[str, BeforeValidator(lambda v: "+" + v if not v.startswith("+") else v)]
4036
my_first_name: str
4137
my_last_name: str
4238

examples/fastmcp/unicode_example.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
mcp = FastMCP()
99

1010

11-
@mcp.tool(
12-
description="🌟 A tool that uses various Unicode characters in its description: "
13-
"á é í ó ú ñ 漢字 🎉"
14-
)
11+
@mcp.tool(description="🌟 A tool that uses various Unicode characters in its description: " "á é í ó ú ñ 漢字 🎉")
1512
def hello_unicode(name: str = "世界", greeting: str = "¡Hola") -> str:
1613
"""
1714
A simple tool that demonstrates Unicode handling in:

0 commit comments

Comments
 (0)