get_project_main
Retrieve project-specific guidelines and configurations from a centralized repository. Use to ensure consistent adherence to project instructions, replace outdated local files, and parse structured content for clarity.
Instructions
Retrieve main.md content for a project's central instructions and configuration.
When to use this tool:
Starting work on any project (ALWAYS use FIRST)
Refreshing your understanding of project guidelines
Checking for updates to project instructions
Migrating from local CLAUDE.md files to centralized storage
Key features:
Replaces need for local CLAUDE.md files completely
Auto-detects project from git repository or directory name
Returns structured content with sections for easy parsing
Provides project-specific instructions and context
You should:
ALWAYS call this first when starting work on a project
Use the returned content as your primary behavioral guide
Check if project exists before assuming it doesn't
Migrate local CLAUDE.md files immediately if project not found
Parse sections to understand project structure and requirements
Treat this as your source of truth over any local files
Remember project_id for subsequent operations
DO NOT use when:
You already have the project content loaded in current session
Working with temporary or test projects
Returns: {exists: bool, content: str, error?: str}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | The project identifier |
Implementation Reference
- Asynchronous implementation of the get_project_main tool handler. Retrieves the content of main.md for the given project_id, or indicates if the project/file does not exist. Called by the MCP server registration.async getProjectMainAsync(params: z.infer<typeof secureProjectIdSchema>): Promise<string> { const context = this.createContext('get_project_main', { project_id: params }); try { const project_id = params; const projectInfo = await getProjectDirectoryAsync(this.storagePath, project_id); // Project doesn't exist - return exists: false if (!projectInfo) { await this.logSuccessAsync('get_project_main', { project_id }, context); return this.formatSuccessResponse({ exists: false, content: '', }); } const [, projectPath] = projectInfo; const mainFile = join(projectPath, 'main.md'); try { await access(mainFile); const content = await readFile(mainFile, 'utf8'); await this.logSuccessAsync('get_project_main', { project_id }, context); return this.formatSuccessResponse({ exists: true, content, }); } catch { await this.logSuccessAsync('get_project_main', { project_id }, context); return this.formatSuccessResponse({ exists: false, content: '', }); } } catch (error) { const mcpError = error instanceof MCPError ? error : new MCPError( MCPErrorCode.PROJECT_NOT_FOUND, `Failed to get project main: ${error instanceof Error ? error.message : String(error)}`, { project_id: params, method: 'get_project_main', traceId: context.traceId } ); await this.logErrorAsync('get_project_main', { project_id: params }, mcpError, context); return this.formatErrorResponse(mcpError, context); } }
- src/knowledge-mcp/server.ts:52-68 (registration)MCP server tool registration for 'get_project_main', defining title, description, input schema, and the async handler invocation.'get_project_main', { title: 'Get Project Main Instructions', description: TOOL_DESCRIPTIONS.get_project_main, inputSchema: { project_id: secureProjectIdSchema.describe('The project identifier'), }, }, async ({ project_id }) => ({ content: [ { type: 'text', text: await projectHandler.getProjectMainAsync(project_id), }, ], }) );
- Zod schema used for validating the project_id input parameter in get_project_main tool. Ensures safe project identifiers without path traversal or reserved chars.export const secureProjectIdSchema = z .string() .min(1, 'Project ID cannot be empty') .max(100, 'Project ID too long') .refine( (val) => !val.includes('..') && !val.startsWith('.') && !val.endsWith('.'), 'Project ID cannot contain path traversal patterns' ) .refine( (val) => !/[/\\:*?"<>|\0]/.test(val), 'Project ID cannot contain filesystem reserved characters or null bytes' ) .refine((val) => val.trim() === val, 'Project ID cannot have leading/trailing spaces');
- Synchronous version of the get_project_main tool handler, mirroring the async implementation for non-async contexts.getProjectMain(params: z.infer<typeof secureProjectIdSchema>): string { const context = this.createContext('get_project_main', { project_id: params }); try { const project_id = params; const projectInfo = getProjectDirectory(this.storagePath, project_id); // Project doesn't exist - return exists: false if (!projectInfo) { this.logSuccess('get_project_main', { project_id }, context); return this.formatSuccessResponse({ exists: false, content: '', }); } const [, projectPath] = projectInfo; const mainFile = join(projectPath, 'main.md'); if (!existsSync(mainFile)) { this.logSuccess('get_project_main', { project_id }, context); return this.formatSuccessResponse({ exists: false, content: '', }); } const content = readFileSync(mainFile, 'utf8'); this.logSuccess('get_project_main', { project_id }, context); return this.formatSuccessResponse({ exists: true, content, }); } catch (error) { const mcpError = error instanceof MCPError ? error : new MCPError( MCPErrorCode.PROJECT_NOT_FOUND, `Failed to get project main: ${error instanceof Error ? error.message : String(error)}`, { project_id: params, method: 'get_project_main', traceId: context.traceId } ); this.logError('get_project_main', { project_id: params }, mcpError, context); return this.formatErrorResponse(mcpError, context); } }