Skip to main content
Glama

loadProto

Load and retrieve content from Protocol Buffer (.proto) files within a specified directory using the MCP server's gRPC-based tools.

Instructions

Load a proto file and return its content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirYesDirectory containing the proto file (e.g., /path/to/proto)

Implementation Reference

  • src/index.ts:44-59 (registration)
    Registration of the MCP tool 'loadProto', including inline input schema and handler function that calls loader.loadAsync on the provided directory and serializes the result to JSON string.
    server.addTool({ name: "loadProto", description: "Load a proto file and return its content", parameters: z.object({ dir: z.string().describe("Directory containing the proto file (e.g., /path/to/proto)"), }), execute: async (args) => { try { const res = await loader.loadAsync(args.dir); return obj2String(res, true); } catch (e) { Logger.error(e); return e instanceof Error ? e.message : "An unknown error occurred"; } }, });
  • Core implementation logic for loading and parsing proto files from a directory: fetches proto definitions, extracts service names and method lists, structures output as array of objects with path and services.
    async loadAsync(dir: string): Promise<Proto[]> { const proto = await protoLoader.loadAsync(dir); const result: Proto[] = []; for (const p of proto) { const services: Service[] = []; for (const s of p.protocolBuffer.services) { services.push({ name: s.name, methods: s.methods.map(m => m.name), }); } result.push({ path: p.protocolBuffer.metadata.protoPath, services: services, }); } return result; },
  • Helper function protoLoader.loadAsync that discovers all .proto files in the directory, loads each asynchronously using loadProtoAsync (which uses @grpc/proto-loader), and returns array of parsed package definitions used by the loader.
    async loadAsync(fileOrDir: string): Promise<ProtocolBufferPackageDefinition[]> { const files = await getFileAsync(fileOrDir, { extensions: [proto_ext] }); const protoTask = files.map((file) => this.loadProtoAsync(file)); return Promise.all(protoTask); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Yuki4-dev/grpc-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server