-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvehicle_info_server.py
More file actions
56 lines (48 loc) · 1.63 KB
/
vehicle_info_server.py
File metadata and controls
56 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import json
import sys
import os
import subprocess
from mcp.server.fastmcp import FastMCP
from typing import Dict, Any
# Initialize FastMCP server
mcp = FastMCP("VehicleInfo")
# Path to the external tool
VEHICLE_INFO_TOOL = os.environ.get("VEHICLE_INFO_TOOL", os.path.join(os.path.dirname(os.path.abspath(__file__)), "vehicle_info_tool.py"))
def run_vehicle_info_tool(license_plate: int) -> Dict[str, Any]:
"""
Run the vehicle info tool as a subprocess and return its output
"""
try:
# Execute the command
process = subprocess.run(
["python", VEHICLE_INFO_TOOL, str(license_plate)],
capture_output=True,
text=True
)
if process.stderr:
print(f"[Tool Error] {process.stderr}", file=sys.stderr)
try:
result = json.loads(process.stdout)
return result
except json.JSONDecodeError:
# If output is not valid JSON, return it as text
return {
"success": False,
"error": "Invalid JSON response",
"output": process.stdout
}
except Exception as e:
return {
"success": False,
"error": str(e)
}
@mcp.tool()
def lookup_vehicle(license_plate: int):
"""Look up vehicle information by license plate number"""
return run_vehicle_info_tool(license_plate)
if __name__ == "__main__":
print("Vehicle Info MCP server running on stdio", file=sys.stderr)
try:
mcp.run(transport="stdio")
except KeyboardInterrupt:
print("\nShutting down server...", file=sys.stderr)