Skip to content

Commit fa932b8

Browse files
committed
get_serveR_details and cmd line arg for client
1 parent c6f9475 commit fa932b8

File tree

2 files changed

+72
-88
lines changed

2 files changed

+72
-88
lines changed

servers/mcpgw/client.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -87,45 +87,48 @@ async def run(server_url, args):
8787
print(f"Error calling 'get_server_details': {e}")
8888
# --- End Example ---
8989

90-
# --- Example: Call the register_service tool ---
91-
print("\nCalling 'register_service' tool with hardcoded parameters")
90+
# --- Example: Call the register_service tool (if enabled) ---
91+
if args.test_register_service and args.test_register_service.lower() in ["true", "yes"]:
92+
print("\nCalling 'register_service' tool with hardcoded parameters")
9293

93-
try:
94-
# Pass hardcoded parameters to the register_service tool
95-
result = await session.call_tool(
96-
"register_service", arguments={
97-
"server_name": "Example Service",
98-
"path": "/example-service",
99-
"proxy_pass_url": "http://localhost:9000",
100-
"description": "An example MCP service for demonstration purposes",
101-
"tags": ["example", "demo", "test"],
102-
"num_tools": 3,
103-
"num_stars": 5,
104-
"is_python": True,
105-
"license": "MIT",
106-
"username": args.username,
107-
"password": args.password
108-
}
109-
)
110-
111-
# Display the results
112-
print("=" * 50)
113-
print("Result for register_service:")
114-
print("=" * 50)
115-
# The result content is usually a list of MessagePart objects
116-
full_response_text = "".join(part.text for part in result.content if hasattr(part, 'text'))
11794
try:
118-
# Attempt to parse and pretty-print if it's JSON
119-
parsed_json = json.loads(full_response_text)
120-
print(json.dumps(parsed_json, indent=2))
121-
except json.JSONDecodeError:
122-
# Otherwise, just print the raw text
123-
print(full_response_text)
124-
print("=" * 50)
125-
126-
except Exception as e:
127-
print(f"Error calling 'register_service': {e}")
128-
# --- End Example ---
95+
# Pass hardcoded parameters to the register_service tool
96+
result = await session.call_tool(
97+
"register_service", arguments={
98+
"server_name": "Example Service",
99+
"path": "/example-service",
100+
"proxy_pass_url": "http://localhost:9000",
101+
"description": "An example MCP service for demonstration purposes",
102+
"tags": ["example", "demo", "test"],
103+
"num_tools": 3,
104+
"num_stars": 5,
105+
"is_python": True,
106+
"license": "MIT",
107+
"username": args.username,
108+
"password": args.password
109+
}
110+
)
111+
112+
# Display the results
113+
print("=" * 50)
114+
print("Result for register_service:")
115+
print("=" * 50)
116+
# The result content is usually a list of MessagePart objects
117+
full_response_text = "".join(part.text for part in result.content if hasattr(part, 'text'))
118+
try:
119+
# Attempt to parse and pretty-print if it's JSON
120+
parsed_json = json.loads(full_response_text)
121+
print(json.dumps(parsed_json, indent=2))
122+
except json.JSONDecodeError:
123+
# Otherwise, just print the raw text
124+
print(full_response_text)
125+
print("=" * 50)
126+
127+
except Exception as e:
128+
print(f"Error calling 'register_service': {e}")
129+
# --- End Example ---
130+
else:
131+
print("\nSkipping 'register_service' tool example (use --test-register-service=true to enable)")
129132

130133

131134
if __name__ == "__main__":
@@ -155,6 +158,12 @@ async def run(server_url, args):
155158
type=str,
156159
help='Password for the MCP Gateway',
157160
)
161+
parser.add_argument(
162+
"--test-register-service",
163+
type=str,
164+
default="false",
165+
help='Set to "true" to test the register_service tool (default: "false")',
166+
)
158167

159168
# Parse the arguments
160169
args = parser.parse_args()

servers/mcpgw/server.py

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -262,57 +262,6 @@ async def toggle_service(
262262
credentials = Credentials(username=username, password=password)
263263
return await _call_registry_api("POST", endpoint, credentials=credentials)
264264

265-
# This implementation has been replaced by the one below
266-
# @mcp.tool()
267-
# async def register_service(
268-
# server_name: str = Field(..., description="Display name for the server."),
269-
# path: str = Field(..., description="Unique URL path prefix for the server (e.g., '/my-service'). Must start with '/'."),
270-
# proxy_pass_url: str = Field(..., description="The internal URL where the actual MCP server is running (e.g., 'http://localhost:8001')."),
271-
# description: Optional[str] = Field(None, description="Optional description of the server."),
272-
# tags: Optional[List[str]] = Field(None, description="Optional list of tags for categorization."),
273-
# is_python: Optional[bool] = Field(False, description="Whether the server is implemented in Python."),
274-
# license: Optional[str] = Field("N/A", description="License information for the server."),
275-
# username: str = Field(..., description="Username for registry authentication"),
276-
# password: str = Field(..., description="Password for registry authentication")
277-
# ) -> Dict[str, Any]:
278-
# """
279-
# Registers a new MCP server with the gateway.
280-
#
281-
# Args:
282-
# server_name: Display name for the server.
283-
# path: Unique URL path prefix for the server (e.g., '/my-service'). Must start with '/'.
284-
# proxy_pass_url: The internal URL where the actual MCP server is running (e.g., 'http://localhost:8001').
285-
# description: Optional description of the server.
286-
# tags: Optional list of tags for categorization.
287-
# is_python: Whether the server is implemented in Python (default: False).
288-
# license: License information for the server (default: 'N/A').
289-
# username: Username for registry authentication.
290-
# password: Password for registry authentication.
291-
#
292-
# Returns:
293-
# Dict[str, Any]: Response from the registry API, likely including the registered server details.
294-
#
295-
# Raises:
296-
# Exception: If the API call fails.
297-
# """
298-
# endpoint = "/register"
299-
# # Extract username and password for credentials
300-
# credentials = Credentials(username=username, password=password)
301-
#
302-
# # Create data to send to the API (excluding username and password)
303-
# data_to_send = {
304-
# "server_name": server_name,
305-
# "path": path,
306-
# "proxy_pass_url": proxy_pass_url,
307-
# "description": description,
308-
# "tags": tags,
309-
# "is_python": is_python,
310-
# "license": license
311-
# }
312-
# # Remove None values
313-
# data_to_send = {k: v for k, v in data_to_send.items() if v is not None}
314-
#
315-
# return await _call_registry_api("POST", endpoint, credentials=credentials, json=data_to_send)
316265

317266
@mcp.tool()
318267
async def register_service(
@@ -426,6 +375,32 @@ async def refresh_service(
426375
return await _call_registry_api("POST", endpoint, credentials=credentials)
427376

428377

378+
@mcp.tool()
379+
async def get_server_details(
380+
service_path: str = Field(..., description="The unique path identifier for the service (e.g., '/fininfo'). Must start with '/'. Use '/all' to get details for all registered servers."),
381+
username: str = Field(..., description="Username for registry authentication"),
382+
password: str = Field(..., description="Password for registry authentication")
383+
) -> Dict[str, Any]:
384+
"""
385+
Retrieves detailed information about a registered MCP server.
386+
387+
Args:
388+
service_path: The unique path identifier for the service (e.g., '/fininfo'). Must start with '/'.
389+
Use '/all' to get details for all registered servers.
390+
username: Username for registry authentication.
391+
password: Password for registry authentication.
392+
393+
Returns:
394+
Dict[str, Any]: Detailed information about the specified server or all servers if '/all' is specified.
395+
396+
Raises:
397+
Exception: If the API call fails or the server is not registered.
398+
"""
399+
endpoint = f"/api/server_details/{service_path.lstrip('/')}"
400+
credentials = Credentials(username=username, password=password)
401+
return await _call_registry_api("GET", endpoint, credentials=credentials)
402+
403+
429404
# --- Main Execution ---
430405

431406
def main():

0 commit comments

Comments
 (0)