get_documentation
Retrieve detailed Apple developer documentation for specific symbols like View, Button, or GridItem to access API references and framework details directly.
Instructions
Get detailed documentation for specific symbols within the selected technology. Use this for known symbol names (e.g., "View", "Button", "GridItem"). Accepts relative symbol names.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Symbol path or relative name (e.g. "View", "GridItem", "Button") |
Implementation Reference
- The exported buildGetDocumentationHandler function creates and returns the core handler logic for the 'get_documentation' tool. It handles fetching symbol data, error fallback for path prefixing, formatting into markdown sections, and returning the response.export const buildGetDocumentationHandler = (context: ServerContext) => { const {client, state} = context; const noTechnology = buildNoTechnologyMessage(context); return async ({path}: {path: string}): Promise<ToolResponse> => { const activeTechnology = state.getActiveTechnology(); if (!activeTechnology) { return noTechnology(); } const framework = await loadActiveFrameworkData(context); const identifierParts = activeTechnology.identifier.split('/'); const frameworkName = identifierParts.at(-1); // Try path as-is first, fallback to framework-prefixed path let targetPath = path; let data: SymbolData; try { // First attempt: try the path exactly as provided data = await client.getSymbol(targetPath); } catch (error) { // If that fails and path doesn't already start with documentation/, // try prefixing with framework path if (path.startsWith('documentation/')) { // Path already starts with documentation/, so just rethrow original error throw error; } else { try { targetPath = `documentation/${frameworkName}/${path}`; data = await client.getSymbol(targetPath); } catch { // If both attempts fail, throw the original error with helpful context throw new McpError( ErrorCode.InvalidRequest, `Failed to load documentation for both "${path}" and "${targetPath}": ${error instanceof Error ? error.message : String(error)}`, ); } } } const title = data.metadata?.title || 'Symbol'; const kind = data.metadata?.symbolKind || 'Unknown'; const platforms = client.formatPlatforms(data.metadata?.platforms ?? framework.metadata.platforms); const description = client.extractText(data.abstract); const content: string[] = [ header(1, title), '', bold('Technology', activeTechnology.title), bold('Type', kind), bold('Platforms', platforms), '', header(2, 'Overview'), description, ]; content.push(...formatTopicSections(data, client)); return { content: [{text: content.join('\n'), type: 'text'}], }; }; };
- src/server/tools.ts:72-87 (registration)The tool definition in the toolDefinitions array, registering the 'get_documentation' tool with its name, description, input schema, and handler reference to the builder function.{ name: 'get_documentation', description: 'Get detailed documentation for specific symbols within the selected technology. ' + 'Use this for known symbol names (e.g., "View", "Button", "GridItem"). Accepts relative symbol names.', inputSchema: { type: 'object', required: ['path'], properties: { path: { type: 'string', description: 'Symbol path or relative name (e.g. "View", "GridItem", "Button")', }, }, }, handler: buildGetDocumentationHandler(context), },
- src/server/tools.ts:76-85 (schema)The inputSchema defining the parameters for the get_documentation tool: an object requiring a 'path' string.inputSchema: { type: 'object', required: ['path'], properties: { path: { type: 'string', description: 'Symbol path or relative name (e.g. "View", "GridItem", "Button")', }, }, },
- Helper function to format topic sections into markdown lists using identifiers and references.const formatTopicSections = (data: SymbolData, client: ServerContext['client']): string[] => { const content: string[] = []; if (data.topicSections?.length) { content.push('', header(2, 'API Reference'), ''); for (const section of data.topicSections) { content.push(`### ${section.title}`); if (section.identifiers?.length) { content.push(...formatIdentifiers(section.identifiers, data.references, client)); } content.push(''); } } return content; };
- Helper function to format a list of identifiers into bulleted markdown items with descriptions, limited to 5 with ellipsis.const formatIdentifiers = (identifiers: string[], references: Record<string, ReferenceData> | undefined, client: ServerContext['client']): string[] => { const content: string[] = []; for (const id of identifiers.slice(0, 5)) { const ref = references?.[id]; if (ref) { const refDesc = client.extractText(ref.abstract ?? []); content.push(`• **${ref.title}** - ${trimWithEllipsis(refDesc, 100)}`); } } if (identifiers.length > 5) { content.push(`*... and ${identifiers.length - 5} more items*`); } return content; };