mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 02:31:29 +00:00
Deduplicates the various `prpc call` subprocess.run calls throughout mcp/ in favor of a new run_prpc_call helper. Also makes a few drive-by cleanup changes that were caught by WIP presubmit checks. Change-Id: I3e401cb959ba96f2224ea1a7f7f58795330f643a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6847120 Commit-Queue: Struan Shrimpton <sshrimp@google.com> Auto-Submit: Brian Sheedy <bsheedy@chromium.org> Reviewed-by: Struan Shrimpton <sshrimp@google.com>
40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
# Copyright 2025 The Chromium Authors
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
"""Common code shared between different MCP server areas."""
|
|
|
|
import json
|
|
import subprocess
|
|
|
|
from mcp.server import fastmcp
|
|
|
|
|
|
async def run_prpc_call(ctx: fastmcp.Context, server: str, service: str,
|
|
message: dict) -> str:
|
|
"""Runs 'prpc call' with the given parameters.
|
|
|
|
Args:
|
|
server: The server the request is for, e.g. cr-buildbucket.appspot.com.
|
|
service: The specific RPC service to call.
|
|
message: The RPC message to send to the service.
|
|
|
|
Returns:
|
|
A string containing the JSON response of the call.
|
|
"""
|
|
command = [
|
|
'prpc',
|
|
'call',
|
|
server,
|
|
service,
|
|
]
|
|
result = subprocess.run(
|
|
command,
|
|
capture_output=True,
|
|
input=json.dumps(message),
|
|
check=True,
|
|
text=True,
|
|
)
|
|
await ctx.info(result.stdout)
|
|
await ctx.info(result.stderr)
|
|
return result.stdout
|