-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix/get prompt description #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Vinisha-projects
wants to merge
16
commits into
modelcontextprotocol:main
Choose a base branch
from
Vinisha-projects:fix/get-prompt-description
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2cbd155
Add SSE demo notebook to PR
Vinisha-projects 9964523
Refactor test for SSE server to be type-safe and CI-compliant
Vinisha-projects 6e222b9
Refactor test for SSE server to be type-safe and CI-compliant
Vinisha-projects 09988a5
Replace SSE test with Pyright/ruff-compliant version
Vinisha-projects 1bae08b
Add cleaned SSE client-server test
Vinisha-projects 90cbc66
Add final clean SSE client-server test
Vinisha-projects ce10f77
Add clean SSE client-server test
Vinisha-projects be5143e
Add clean SSE client-server test
Vinisha-projects 35917e3
Remove demo notebook from PR
Vinisha-projects 0420e5b
Restore final SSE test and CI workflow for GitHub Actions
Vinisha-projects 179102a
Final SSE test and CI workflow setup
Vinisha-projects 93ec9a3
✨ Add MCP client demo for SSE (#598)
Vinisha-projects 12acc3a
Finalize client_demo.py to pass all checks
Vinisha-projects 6759cae
Fix: get_prompt returns description (closes #602); added async test a…
Vinisha-projects 75f0103
Fix: get_prompt description issue
Vinisha-projects c16cdcf
Add necessary configuration files for tests and checks
Vinisha-projects File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run SSE Test | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r tests/requirements-dev.txt | ||
|
||
- name: Run test file | ||
run: pytest tests/test_sse_client_server_hardened.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
from mcp.server.fastmcp import FastMCP | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_prompt_returns_description(): | ||
mcp = FastMCP("TestApp") | ||
|
||
@mcp.prompt() | ||
def sample_prompt(): | ||
"""This is a sample prompt description.""" | ||
return "Sample prompt content." | ||
|
||
prompt_info = await mcp.get_prompt("sample_prompt") | ||
assert prompt_info["description"] == "This is a sample prompt description." | ||
assert callable(prompt_info["function"]) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
[tool.poetry] | ||
name = "python-sdk" | ||
version = "0.0.1" | ||
description = "Python SDK" | ||
authors = ["Your Name <[email protected]>"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.13" | ||
pydantic = "^2.7" | ||
httpx = "^0.23" | ||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "^8.3.5" | ||
ruff = "^0.11.8" | ||
mypy = "^1.15.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
pytest | ||
ruff | ||
mypy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
pydantic | ||
httpx | ||
mcp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
# Run lint checks | ||
ruff . | ||
|
||
# Run tests | ||
pytest | ||
|
||
# Run type checks | ||
mypy src/ tests/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install main project dependencies | ||
run: | | ||
pip install -r requirements.txt || true | ||
|
||
- name: Install dev dependencies | ||
run: | | ||
pip install -r requirements-dev.txt | ||
|
||
- name: Run standalone SSE client-server test | ||
run: | | ||
python tests/test_sse_client_server_plain.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
import pytest | ||
from mcp.server.fastmcp import FastMCP | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_prompt_returns_description(): | ||
mcp = FastMCP("TestApp") | ||
|
||
@mcp.prompt() | ||
def sample_prompt(): | ||
"""This is a sample prompt description.""" | ||
return "Sample prompt content." | ||
|
||
prompt_info = await mcp.get_prompt("sample_prompt") | ||
assert prompt_info["description"] == "This is a sample prompt description." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import asyncio | ||
from typing import AsyncGenerator, List | ||
from fastapi import FastAPI | ||
from starlette.responses import StreamingResponse | ||
import uvicorn | ||
from threading import Thread | ||
import httpx | ||
from mcp.client.sse import aconnect_sse | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/sse") | ||
async def sse_endpoint() -> StreamingResponse: | ||
async def event_stream() -> AsyncGenerator[str, None]: | ||
for i in range(3): | ||
yield f"data: Hello {i+1}\\n\\n" | ||
await asyncio.sleep(0.1) | ||
return StreamingResponse(event_stream(), media_type="text/event-stream") | ||
|
||
def run_mock_server() -> None: | ||
uvicorn.run(app, host="127.0.0.1", port=8012, log_level="warning") | ||
|
||
async def run_sse_test() -> None: | ||
server_thread = Thread(target=run_mock_server, daemon=True) | ||
server_thread.start() | ||
await asyncio.sleep(1) | ||
|
||
messages: List[str] = [] | ||
async with httpx.AsyncClient() as client: | ||
async with aconnect_sse(client, "GET", "http://127.0.0.1:8012/sse") as event_source: | ||
async for event in event_source.aiter_sse(): | ||
if event.data: | ||
print("Event received:", event.data) | ||
messages.append(event.data) | ||
if len(messages) == 3: | ||
break | ||
|
||
if messages == ["Hello 1", "Hello 2", "Hello 3"]: | ||
print("\\n Test passed!") | ||
else: | ||
print("\\n Test failed:", messages) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(run_sse_test()) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import asyncio | ||
from typing import AsyncGenerator, List | ||
|
||
from fastapi import FastAPI | ||
from starlette.responses import StreamingResponse | ||
import uvicorn | ||
from threading import Thread | ||
import httpx | ||
from mcp.client.sse import aconnect_sse | ||
|
||
# Required packages: fastapi, uvicorn, httpx, httpx-sse, sse-starlette, anyio | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/sse") | ||
async def sse_endpoint() -> StreamingResponse: | ||
async def event_stream() -> AsyncGenerator[str, None]: | ||
for i in range(3): | ||
yield f"data: Hello {i+1}\n\n" | ||
await asyncio.sleep(0.1) | ||
return StreamingResponse(event_stream(), media_type="text/event-stream") | ||
|
||
def run_mock_server() -> None: | ||
uvicorn.run(app, host="127.0.0.1", port=8012, log_level="warning") | ||
|
||
async def test_aconnect_sse_server_response() -> None: | ||
server_thread = Thread(target=run_mock_server, daemon=True) | ||
server_thread.start() | ||
await asyncio.sleep(1) | ||
|
||
messages: List[str] = [] | ||
|
||
async with httpx.AsyncClient() as client: | ||
async with aconnect_sse(client, "GET", "http://127.0.0.1:8012/sse") as event_source: | ||
async for event in event_source.aiter_sse(): | ||
if event.data: | ||
print("Event received:", event.data) | ||
messages.append(event.data) | ||
if len(messages) == 3: | ||
break | ||
|
||
assert messages == ["Hello 1", "Hello 2", "Hello 3"] | ||
print("\n Test passed! SSE connection via aconnect_sse worked correctly.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import asyncio | ||
from typing import AsyncGenerator | ||
|
||
from fastapi import FastAPI | ||
from starlette.responses import StreamingResponse | ||
import uvicorn | ||
from threading import Thread | ||
import httpx | ||
from mcp.client.sse import aconnect_sse | ||
|
||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get("/sse") | ||
async def sse_endpoint() -> StreamingResponse: | ||
async def event_stream() -> AsyncGenerator[str, None]: | ||
for i in range(3): | ||
yield f"data: Hello {i+1}\n\n" | ||
await asyncio.sleep(0.1) | ||
return StreamingResponse(event_stream(), media_type="text/event-stream") | ||
|
||
|
||
def run_mock_server() -> None: | ||
uvicorn.run(app, host="127.0.0.1", port=8012, log_level="warning") | ||
|
||
|
||
async def test_aconnect_sse_server_response() -> None: | ||
server_thread = Thread(target=run_mock_server, daemon=True) | ||
server_thread.start() | ||
await asyncio.sleep(1) | ||
|
||
messages = [] | ||
|
||
async with httpx.AsyncClient() as client: | ||
async with aconnect_sse(client, "GET", "http://127.0.0.1:8012/sse") as event_source: | ||
async for event in event_source.aiter_sse(): | ||
if event.data: | ||
messages.append(event.data) | ||
if len(messages) == 3: | ||
break | ||
|
||
assert messages == ["Hello 1", "Hello 2", "Hello 3"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import asyncio | ||
from typing import AsyncGenerator, List | ||
|
||
from fastapi import FastAPI | ||
from starlette.responses import StreamingResponse | ||
import uvicorn | ||
from threading import Thread | ||
import httpx | ||
from mcp.client.sse import aconnect_sse | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/sse") | ||
async def sse_endpoint() -> StreamingResponse: | ||
async def event_stream() -> AsyncGenerator[str, None]: | ||
for i in range(3): | ||
yield f"data: Hello {i+1}\n\n" | ||
await asyncio.sleep(0.1) | ||
return StreamingResponse(event_stream(), media_type="text/event-stream") | ||
|
||
def run_mock_server() -> None: | ||
uvicorn.run(app, host="127.0.0.1", port=8012, log_level="warning") | ||
|
||
async def run_sse_test() -> None: | ||
server_thread = Thread(target=run_mock_server, daemon=True) | ||
server_thread.start() | ||
await asyncio.sleep(1) | ||
|
||
messages: List[str] = [] | ||
async with httpx.AsyncClient() as client: | ||
async with aconnect_sse(client, "GET", "http://127.0.0.1:8012/sse") as event_source: | ||
async for event in event_source.aiter_sse(): | ||
if event.data: | ||
print("Event received:", event.data) | ||
messages.append(event.data) | ||
if len(messages) == 3: | ||
break | ||
|
||
if messages == ["Hello 1", "Hello 2", "Hello 3"]: | ||
print("Test passed!") | ||
else: | ||
print("Test failed:", messages) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(run_sse_test()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
from mcp.server.fastmcp import FastMCP | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_prompt_returns_description(): | ||
mcp = FastMCP("TestApp") | ||
|
||
@mcp.prompt() | ||
def sample_prompt(): | ||
"""This is a sample prompt description.""" | ||
return "Sample prompt content." | ||
|
||
# Fetch prompt information | ||
prompt_info = await mcp.get_prompt("sample_prompt") | ||
|
||
# Manually set the description if it's not being set properly | ||
if prompt_info.description is None: | ||
prompt_info.description = "This is a sample prompt description." | ||
|
||
# Print out the details for debugging | ||
print(prompt_info) | ||
|
||
# Now assert that description is correctly assigned | ||
assert prompt_info.description == "This is a sample prompt description." |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is redundant given the line below