set-project-id
Set the default Google Cloud project ID for subsequent operations in the MCP server, enabling streamlined access to services like Logging, Spanner, Monitoring, and Cloud Trace.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"projectId": "<projectId>"
},
"name": "set-project-id"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | The Google Cloud project ID to set as default |
Implementation Reference
- src/utils/project-tools.ts:23-42 (handler)The asynchronous handler function for the 'set-project-id' tool. It calls setProjectId(projectId), handles errors, and returns markdown content indicating success or failure.
async ({ projectId }, context) => { try { await setProjectId(projectId); return { content: [{ type: 'text', text: `# Project ID Updated\n\nDefault Google Cloud project ID has been set to: \`${projectId}\`\n\nThis project ID will be used for all Google Cloud operations until changed.` }] }; } catch (error: any) { // Error handling for set-project-id tool return { content: [{ type: 'text', text: `# Error Setting Project ID\n\nFailed to set project ID: ${error.message}` }] }; } } - src/utils/project-tools.ts:21-22 (schema)Zod input schema for the 'set-project-id' tool defining the required projectId string parameter.
projectId: z.string().describe('The Google Cloud project ID to set as default') }, - src/utils/project-tools.ts:18-43 (registration)Registration of the 'set-project-id' tool on the MCP server instance within registerProjectTools, including schema and handler.
server.tool( 'set-project-id', { projectId: z.string().describe('The Google Cloud project ID to set as default') }, async ({ projectId }, context) => { try { await setProjectId(projectId); return { content: [{ type: 'text', text: `# Project ID Updated\n\nDefault Google Cloud project ID has been set to: \`${projectId}\`\n\nThis project ID will be used for all Google Cloud operations until changed.` }] }; } catch (error: any) { // Error handling for set-project-id tool return { content: [{ type: 'text', text: `# Error Setting Project ID\n\nFailed to set project ID: ${error.message}` }] }; } } ); - src/index.ts:165-165 (registration)Top-level call to registerProjectTools(server) in the main server setup, which includes registration of the set-project-id tool.
registerProjectTools(server); - src/utils/auth.ts:232-235 (helper)Helper function setProjectId that persists the project ID using the state manager, called by the tool handler.
export async function setProjectId(projectId: string): Promise<void> { // Use the state manager to set the project ID await stateManager.setCurrentProjectId(projectId); }