Skip to content

Commit 27a1518

Browse files
feat: Add contextual documentation retrieval tool
Implements get_contextual_docs_tool for intelligent documentation retrieval based on user context, code snippets, and error messages. Features: - Context-aware keyword extraction from text, code, and errors - Intelligent relevance scoring with match explanations - Troubleshooting tips for error messages - Technology-specific filtering (mapbox-gl-js, iOS SDK, Android SDK) - Suggested related topics - Ranked results with excerpts and direct documentation links - 1-hour caching for performance Smarter than simple search - understands full context and provides actionable, targeted documentation guidance. Addresses: #70 Changes: - Add GetContextualDocsTool implementation - Register in toolRegistry.ts - Add comprehensive test coverage (13 tests) - Update CHANGELOG.md with feature details - Update README.md with tool documentation and examples - All 549 tests passing Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 0646781 commit 27a1518

8 files changed

Lines changed: 997 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
## Unreleased
22

3+
### Features Added
4+
5+
- **Contextual Documentation Tool**: New `get_contextual_docs_tool` provides intelligent documentation retrieval based on context (#70)
6+
- Analyzes what you're working on, code snippets, and error messages
7+
- Extracts keywords automatically from context, code, and errors
8+
- Returns ranked, relevant documentation with explanations
9+
- Provides troubleshooting tips for error messages
10+
- Suggests related topics to explore
11+
- Smarter than simple search - understands full context
12+
- Technology-specific filtering (mapbox-gl-js, iOS SDK, Android SDK)
13+
- 1-hour caching for performance
14+
315
### Documentation
416

517
- **PR Guidelines**: Added CHANGELOG requirement to CLAUDE.md (#67)

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,25 @@ The `MAPBOX_ACCESS_TOKEN` environment variable is required. **Each tool requires
131131

132132
📖 **[See more examples and interactive demo →](./docs/mapbox-docs-tool-demo.md)**
133133

134+
**get_contextual_docs_tool** - Retrieve relevant Mapbox documentation based on your current context. This smart tool analyzes what you're working on, code snippets, and error messages to provide targeted, actionable documentation.
135+
136+
**Features:**
137+
138+
- Context-aware keyword extraction from descriptions, code, and errors
139+
- Intelligent relevance scoring with match explanations
140+
- Troubleshooting tips for error messages
141+
- Technology-specific filtering (mapbox-gl-js, iOS SDK, Android SDK)
142+
- Suggested related topics to explore
143+
- Ranked results with excerpts and direct links
144+
145+
**Example prompts:**
146+
147+
- "I'm trying to add custom markers with popups, here's my code: [snippet]"
148+
- "Getting this error: 'Style is not done loading' - what does it mean?"
149+
- "Working with mapbox-gl-js to show user location on a map"
150+
- "How do I handle rate limiting errors in the geocoding API?"
151+
- "Building a store locator with search functionality"
152+
134153
### Reference Tools
135154

136155
**get_reference_tool** - Access static Mapbox reference documentation and schemas. This tool provides essential reference information that helps AI assistants understand Mapbox concepts and build correct styles and tokens.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { z } from 'zod';
2+
3+
/**
4+
* Input schema for GetContextualDocsTool
5+
*
6+
* This tool retrieves relevant Mapbox documentation based on the user's
7+
* current context, including what they're working on, code snippets,
8+
* and error messages.
9+
*/
10+
export const GetContextualDocsInputSchema = z.object({
11+
context: z
12+
.string()
13+
.min(1)
14+
.describe(
15+
'Description of what the user is working on or trying to accomplish (e.g., "adding custom markers with popups")'
16+
),
17+
18+
codeSnippet: z
19+
.string()
20+
.optional()
21+
.describe(
22+
'Optional code snippet being worked with. Helps identify the specific APIs and patterns being used.'
23+
),
24+
25+
errorMessage: z
26+
.string()
27+
.optional()
28+
.describe(
29+
'Optional error message to help diagnose issues and find relevant troubleshooting documentation.'
30+
),
31+
32+
technology: z
33+
.string()
34+
.optional()
35+
.describe(
36+
'Specific SDK or platform being used (e.g., "mapbox-gl-js", "ios-sdk", "android-sdk")'
37+
),
38+
39+
limit: z
40+
.number()
41+
.int()
42+
.min(1)
43+
.max(10)
44+
.optional()
45+
.default(5)
46+
.describe(
47+
'Maximum number of documentation results to return (1-10, default: 5)'
48+
)
49+
});
50+
51+
/**
52+
* Inferred TypeScript type for GetContextualDocsTool input
53+
*/
54+
export type GetContextualDocsInput = z.infer<
55+
typeof GetContextualDocsInputSchema
56+
>;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { z } from 'zod';
2+
3+
/**
4+
* Schema for a single documentation result
5+
*/
6+
const DocResultSchema = z.object({
7+
title: z.string().describe('Title of the documentation section'),
8+
excerpt: z
9+
.string()
10+
.describe(
11+
'Relevant excerpt from the documentation showing key information'
12+
),
13+
category: z
14+
.string()
15+
.describe('Category of documentation (apis, sdks, guides, examples)'),
16+
url: z.string().describe('Full URL to the documentation page'),
17+
relevanceScore: z
18+
.number()
19+
.describe(
20+
'Relevance score from 0-1 indicating how well this matches the context'
21+
),
22+
matchReason: z
23+
.string()
24+
.optional()
25+
.describe(
26+
'Explanation of why this documentation is relevant to the context'
27+
)
28+
});
29+
30+
/**
31+
* Output schema for GetContextualDocsTool
32+
*/
33+
export const GetContextualDocsOutputSchema = z.object({
34+
results: z
35+
.array(DocResultSchema)
36+
.describe('Ranked list of relevant documentation sections'),
37+
extractedKeywords: z
38+
.array(z.string())
39+
.describe('Key concepts extracted from the provided context'),
40+
suggestedTopics: z
41+
.array(z.string())
42+
.optional()
43+
.describe('Related topics the user might want to explore'),
44+
troubleshootingTips: z
45+
.array(z.string())
46+
.optional()
47+
.describe('Troubleshooting suggestions if an error message was provided'),
48+
totalResults: z.number().describe('Total number of results found'),
49+
context: z.string().describe('The original context provided')
50+
});
51+
52+
/**
53+
* Inferred TypeScript type for GetContextualDocsTool output
54+
*/
55+
export type GetContextualDocsOutput = z.infer<
56+
typeof GetContextualDocsOutputSchema
57+
>;

0 commit comments

Comments
 (0)