set-project-id
Set the default Google Cloud project ID for querying and interacting with services like Logging, Spanner, Monitoring, and Cloud Trace via the MCP server.
Input Schema
TableJSON 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 handler function for the 'set-project-id' MCP tool. It calls the setProjectId helper, handles errors, and returns a markdown-formatted response.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:20-22 (schema)Zod input schema defining the required 'projectId' string parameter for the tool.{ projectId: z.string().describe('The Google Cloud project ID to set as default') },
- src/utils/project-tools.ts:18-43 (registration)The server.tool call that registers the 'set-project-id' tool with the MCP server, 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 function, which includes registration of the set-project-id tool.registerProjectTools(server);
- src/utils/auth.ts:232-235 (helper)Helper function called by the tool handler to persist the project ID in the state manager.export async function setProjectId(projectId: string): Promise<void> { // Use the state manager to set the project ID await stateManager.setCurrentProjectId(projectId); }