Skip to content

Commit f44ff8d

Browse files
committed
improve tests
1 parent 96be3f4 commit f44ff8d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

examples/simple_integration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Simple example of using FastAPI-MCP to add an MCP server to a FastAPI app.
33
"""
44

5-
from fastapi import FastAPI, Query
5+
from fastapi import FastAPI, HTTPException, Query
66
from pydantic import BaseModel
77
from typing import List, Optional
88

@@ -27,7 +27,7 @@ class Item(BaseModel):
2727

2828

2929
# In-memory database
30-
items_db = {}
30+
items_db: dict[int, Item] = {}
3131

3232

3333
# Define some endpoints
@@ -49,7 +49,7 @@ async def read_item(item_id: int):
4949
Raises a 404 error if the item does not exist.
5050
"""
5151
if item_id not in items_db:
52-
return {"error": "Item not found"}
52+
raise HTTPException(status_code=404, detail="Item not found")
5353
return items_db[item_id]
5454

5555

@@ -72,7 +72,7 @@ async def update_item(item_id: int, item: Item):
7272
Raises a 404 error if the item does not exist.
7373
"""
7474
if item_id not in items_db:
75-
return {"error": "Item not found"}
75+
raise HTTPException(status_code=404, detail="Item not found")
7676

7777
item.id = item_id
7878
items_db[item_id] = item
@@ -87,7 +87,7 @@ async def delete_item(item_id: int):
8787
Raises a 404 error if the item does not exist.
8888
"""
8989
if item_id not in items_db:
90-
return {"error": "Item not found"}
90+
raise HTTPException(status_code=404, detail="Item not found")
9191

9292
del items_db[item_id]
9393
return {"message": "Item deleted successfully"}

test_mcp_tools.py renamed to tests/manual_test_mcp_tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
This script connects to the MCP server, initializes a session, and requests a list of available tools.
55
"""
66

7+
# TODO: Turn this into a pytest test
8+
79
import json
810
import sys
911
import asyncio

tests/test_http_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pytest
77
from fastapi import FastAPI, Query, Path, Body
88
from pydantic import BaseModel
9-
from typing import List, Optional, Dict, Any
9+
from typing import List, Optional
1010

1111
from fastapi_mcp import add_mcp_server
1212
from fastapi_mcp.http_tools import (

0 commit comments

Comments
 (0)