Skip to content

Commit 8a7d9e1

Browse files
committed
refactor/use strict types for endpoint index
1 parent be28489 commit 8a7d9e1

5 files changed

Lines changed: 605 additions & 11 deletions

File tree

src/mcp_server_obp/elicitation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ApprovalConsent:
99
consent_id: str
1010

1111

12-
def get_required_entitlements(endpoint: dict[str, Any]) -> list[str]:
12+
def get_roles(endpoint: dict[str, Any]) -> list[str]:
1313
"""
1414
Gets the required entitlements for a given OBP endpoint.
1515
"""

src/mcp_server_obp/server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ def list_endpoints_by_tag(tags: List[str]) -> str:
8383
"total_endpoints": len(index._index)
8484
}, indent=2)
8585

86+
# Serialize Pydantic models to dictionaries
8687
return json.dumps({
8788
"count": len(endpoints),
88-
"endpoints": endpoints
89+
"endpoints": [ep.model_dump() for ep in endpoints]
8990
}, indent=2)
9091

9192
except Exception as e:
@@ -132,7 +133,8 @@ def get_endpoint_schema(endpoint_id: str) -> str:
132133
"suggestion": "Use list_endpoints_by_tag() to find available endpoints"
133134
}, indent=2)
134135

135-
return json.dumps(schema, indent=2)
136+
# Serialize Pydantic model to dictionary
137+
return json.dumps(schema.model_dump(by_alias=True), indent=2)
136138

137139
except Exception as e:
138140
logger.error(f"Error getting endpoint schema: {e}")
@@ -188,7 +190,7 @@ def call_obp_api(
188190
}, indent=2)
189191

190192
# Construct the path with parameters
191-
path = endpoint["path"]
193+
path = endpoint.path
192194
if path_params:
193195
for key, value in path_params.items():
194196
path = path.replace(f"{{{key}}}", str(value))
@@ -200,7 +202,7 @@ def call_obp_api(
200202
url = f"{base_url}{path}"
201203

202204
# Prepare request
203-
method = endpoint["method"].upper()
205+
method = endpoint.method.value # HttpMethod enum value
204206
request_headers = headers or {}
205207

206208
# Make the request

src/tools/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Tools package for OBP-MCP server."""
2+
3+
from src.tools.endpoint_index import (
4+
EndpointIndex,
5+
EndpointSummary,
6+
EndpointSchema,
7+
EndpointParameter,
8+
EndpointResponse,
9+
HttpMethod,
10+
get_endpoint_index,
11+
reload_endpoint_index,
12+
)
13+
14+
__all__ = [
15+
"EndpointIndex",
16+
"EndpointSummary",
17+
"EndpointSchema",
18+
"EndpointParameter",
19+
"EndpointResponse",
20+
"HttpMethod",
21+
"get_endpoint_index",
22+
"reload_endpoint_index",
23+
]

0 commit comments

Comments
 (0)