Skip to content

Commit 05a7953

Browse files
[docs] Update CLAUDE and other agent docs (#76)
1 parent eed8230 commit 05a7953

File tree

5 files changed

+233
-296
lines changed

5 files changed

+233
-296
lines changed

.github/copilot-instructions.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
# GitHub Copilot Usage & Standards for Mapbox MCP Server
1+
# GitHub Copilot Guidelines for Mapbox MCP Server
22

3-
This document defines how to use GitHub Copilot effectively and responsibly in the Mapbox MCP server repository. Following these guidelines ensures Copilot is a productive tool that supports, but does not replace, our engineering standards.
3+
This document defines responsible use of GitHub Copilot in this repository. Copilot is a productivity tool that must work within our engineering standards.
44

5-
---
5+
## Core Principles
66

7-
## 1. Copilot as an Assistant, Not an Authority
7+
### 1. Review, Don't Auto-Accept
88

9-
- **Review All Suggestions:** Never accept Copilot code without reviewing it for correctness, security, and style.
10-
- **Understand Before You Use:** Only use Copilot suggestions you fully understand. If unsure, ask for clarification or write it yourself.
11-
- **No Blind Copy-Paste:** Do not copy-paste large blocks of Copilot code without adapting to project context.
9+
- **Always review** Copilot suggestions before accepting
10+
- **Understand first** - only use code you fully comprehend
11+
- **No blind copy-paste** - adapt suggestions to project context
12+
- **Iterate** - use suggestions as starting points, not final solutions
1213

13-
---
14+
### 2. Security First
1415

15-
## 2. Code Quality & Consistency
16+
- **Never accept** suggestions with hardcoded secrets, tokens, or credentials
17+
- **Review carefully** any code handling sensitive data
18+
- **Environment variables** - ensure secrets use `.env` files, never committed
1619

17-
- **Follow Project Standards:** All Copilot-generated code must comply with the standards in `CLAUDE.md` and our linting, typing, and testing requirements.
18-
- **TypeScript Only:** Copilot suggestions must be in TypeScript for all code in `src/` and `test/`.
19-
- **No Global Pollution:** Do not accept suggestions that patch or override global objects (e.g., `global.fetch`).
20+
### 3. Quality Standards
2021

21-
---
22+
- All Copilot code must comply with standards in **CLAUDE.md** and **docs/engineering_standards.md**
23+
- Pre-commit hooks will enforce linting, formatting, and TypeScript strictness
24+
- If Copilot suggests patterns inconsistent with the codebase, reject and write manually
2225

23-
## 3. Testing & Documentation
26+
### 4. Testing & Documentation
2427

25-
- **Tests Required:** All Copilot-generated features or fixes must include appropriate unit tests.
26-
- **JSDoc & Comments:** Add or edit documentation/comments for Copilot code as you would for hand-written code.
27-
28-
---
28+
- Include unit tests for all Copilot-generated features or fixes
29+
- Add or update JSDoc comments as you would for hand-written code
30+
- Update README.md or CHANGELOG.md if user-facing changes
2931

30-
## 4. Security & Privacy
32+
### 5. Collaboration
3133

32-
- **No Secrets:** Never accept suggestions that include hardcoded secrets, tokens, or credentials.
33-
- **Sensitive Data:** Do not use Copilot to generate or handle sensitive data without review.
34+
- All Copilot code goes through standard PR review process
35+
- Mention in PR description if significant portion is Copilot-generated
36+
- Provide feedback if Copilot produces poor/unsafe suggestions
3437

35-
---
38+
## When to Avoid Copilot
3639

37-
## 5. Collaboration & Review
40+
- **Critical business logic** - prefer hand-written code with thorough review
41+
- **Security-sensitive code** - authentication, authorization, data validation
42+
- **Legal/compliance code** - licensing, terms of service, privacy policies
43+
- **Architecture decisions** - let humans make strategic choices
3844

39-
- **Pull Requests:** All Copilot-generated code must go through the standard PR review process.
40-
- **Attribution:** If a significant portion of a PR is Copilot-generated, mention it in the PR description.
41-
- **Feedback:** If Copilot produces poor or unsafe suggestions, provide feedback to improve future results.
45+
## Learning from the Codebase
4246

43-
---
47+
Copilot learns patterns from existing code. This codebase has strong conventions:
4448

45-
## 6. When Not to Use Copilot
49+
- Dependency injection for testability (see src/tools/)
50+
- HttpPipeline for all HTTP requests (see src/utils/httpPipeline.ts)
51+
- Consistent tool structure extending MapboxApiBasedTool
4652

47-
- **Complex Business Logic:** For critical or complex business logic, prefer hand-written code and thorough review.
48-
- **Legal/Compliance Code:** Do not use Copilot for code with legal, licensing, or compliance implications without explicit review.
53+
Let Copilot learn these patterns rather than explicitly re-teaching them.
4954

5055
---
5156

52-
## 7. Continuous Improvement
53-
54-
- **Iterate:** Use Copilot to explore solutions, but always iterate and refine.
55-
- **Propose Improvements:** Suggest updates to this document as Copilot and our practices evolve.
56-
57-
---
57+
**Remember**: Copilot is an assistant, not an authority. You own the code you commit.

AGENTS.md

Lines changed: 54 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
# AI Agent Instructions for Mapbox MCP Server
22

3-
## Project Overview
3+
> **Note**: If you're using Claude Code specifically, see CLAUDE.md instead. This file is for general AI coding assistants.
44
5-
This is a Model Context Protocol (MCP) server that provides AI agents with access to Mapbox's geospatial services including geocoding, directions, search, and mapping capabilities. The server implements tools for forward/reverse geocoding, route planning, point-of-interest search, static map generation, and geographic data analysis.
5+
## What This Project Does
66

7-
## Architecture & Standards
7+
This is an MCP (Model Context Protocol) server that provides AI applications with geospatial intelligence capabilities through Mapbox APIs. It enables AI agents to understand locations, navigate the physical world, and access spatial data including geocoding, search, routing, travel time analysis, and map visualization.
88

9-
### Core Technologies
9+
## Tech Stack
1010

11-
- **Runtime:** Node.js LTS
12-
- **Language:** TypeScript (strict mode, no JavaScript files)
13-
- **Testing:** Vitest with comprehensive unit tests
14-
- **Package Management:** npm
15-
- **Code Quality:** ESLint + Prettier, pre-commit hooks
11+
- **Runtime**: Node.js 22+ LTS
12+
- **Language**: TypeScript (strict mode)
13+
- **Testing**: Vitest
14+
- **Package Manager**: npm
1615

17-
### Key Design Patterns
18-
19-
- **Policy Pipeline Architecture:** All HTTP requests use `PolicyPipeline` with configurable policies (UserAgent, Retry, etc.)
20-
- **Dependency Injection:** Tools accept fetch functions/pipelines via constructor for testability
21-
- **No Global Pollution:** Avoid patching global objects; use explicit dependency injection
22-
- **Tool Registration:** Standard MCP tool interface with schema validation
23-
24-
### Project Structure
16+
## Project Structure
2517

2618
```
2719
src/
@@ -31,161 +23,71 @@ src/
3123
│ ├── MapboxApiBasedTool.ts # Base class for Mapbox API tools
3224
│ ├── toolRegistry.ts # Tool registration system
3325
│ └── */Tool.ts # Individual tool implementations
26+
├── resources/ # MCP resources (static data)
27+
│ └── resourceRegistry.ts
3428
└── utils/
35-
├── fetchRequest.ts # HTTP policy pipeline system
36-
└── versionUtils.ts # Version info utilities
29+
├── httpPipeline.ts # HTTP policy pipeline system
30+
└── tracing.ts # OpenTelemetry instrumentation
3731
38-
test/ # Mirror src/ structure for tests
32+
test/ # Mirrors src/ structure
3933
```
4034

41-
## Code Quality Guidelines
42-
43-
### TypeScript Standards
44-
45-
- Use strict typing; avoid `any` unless justified with comments
46-
- All public APIs require JSDoc documentation
47-
- Follow naming conventions: PascalCase for classes, camelCase for functions/variables
48-
- Export interfaces and types for external consumption
49-
50-
### Testing Requirements
51-
52-
- **Coverage:** Aim for 100% on critical business logic
53-
- **Isolation:** Mock external APIs; no real network calls in tests
54-
- **Structure:** Tests mirror `src/` directory structure
55-
- **Framework:** Use Vitest exclusively; leverage `vi.fn()` for mocking
56-
57-
### HTTP Request Handling
58-
59-
```typescript
60-
// Correct: Use PolicyPipeline with dependency injection
61-
const pipeline = new PolicyPipeline();
62-
pipeline.usePolicy(new UserAgentPolicy(userAgent));
63-
pipeline.usePolicy(new RetryPolicy(3, 200, 2000));
64-
65-
class MyTool extends MapboxApiBasedTool {
66-
constructor(fetch: typeof fetch = fetchClient) {
67-
super({ inputSchema: MySchema });
68-
this.fetch = fetch;
69-
}
70-
}
71-
72-
// Incorrect: Global fetch patching
73-
global.fetch = myCustomFetch; // ❌ Don't do this
74-
```
75-
76-
### Error Handling
77-
78-
- Handle and log errors gracefully
79-
- Don't swallow exceptions without proper logging
80-
- Use appropriate HTTP status codes
81-
- Provide meaningful error messages to users
35+
## Critical Patterns
8236

83-
## Development Workflow
37+
### HTTP Request Architecture
8438

85-
### Pull Request Standards
39+
- **Never patch global.fetch** - use `HttpPipeline` with dependency injection
40+
- All HTTP requests flow through the pipeline system (src/utils/httpPipeline.ts:21)
41+
- Tools receive `httpRequest` via constructor (src/tools/toolRegistry.ts:22-29)
8642

87-
1. **Size:** Keep PRs focused and reasonably sized
88-
2. **Testing:** Include unit tests for all new functionality
89-
3. **Documentation:** Update README.md, CHANGELOG.md as needed
90-
4. **Review:** Require approval from core maintainer
91-
5. **CI:** All tests and linting must pass
92-
93-
### Commit Standards
94-
95-
- Use conventional commit format
96-
- Reference GitHub issues where applicable
97-
- Include breaking change notes in commit body
98-
99-
### Security Guidelines
100-
101-
- **No Secrets:** Never commit API keys, tokens, or credentials
102-
- **Environment Variables:** Use `.env` files (git-ignored) for local development
103-
- **Dependencies:** Keep packages updated; monitor for vulnerabilities
104-
- **Code Review:** Security-sensitive changes require thorough review
105-
106-
## Tool Development Patterns
107-
108-
### Creating New Tools
109-
110-
1. Extend `MapboxApiBasedTool<T>` base class
111-
2. Define input schema with Zod validation
112-
3. Implement `execute()` method with proper error handling
113-
4. Accept fetch function via constructor for testability
114-
5. Include comprehensive unit tests
115-
116-
### Example Tool Structure
117-
118-
```typescript
119-
export class ExampleTool extends MapboxApiBasedTool<typeof ExampleSchema> {
120-
name = 'example_tool';
121-
description = 'Tool description for AI agents';
122-
123-
constructor(fetch: typeof fetch = fetchClient) {
124-
super({ inputSchema: ExampleSchema });
125-
this.fetch = fetch;
126-
}
127-
128-
protected async execute(
129-
input: z.infer<typeof ExampleSchema>,
130-
accessToken: string
131-
): Promise<{ type: 'text'; text: string }> {
132-
// Implementation
133-
}
134-
}
135-
```
43+
### Tool Development
13644

137-
### Testing Tools
45+
- Extend `MapboxApiBasedTool` base class (src/tools/MapboxApiBasedTool.ts:16)
46+
- Accept `httpRequest` parameter in constructor for testability
47+
- Register in `ALL_TOOLS` array (src/tools/toolRegistry.ts:18)
48+
- Use `npx plop create-tool` for scaffolding new tools
13849

139-
```typescript
140-
describe('ExampleTool', () => {
141-
beforeEach(() => {
142-
vi.stubEnv('MAPBOX_ACCESS_TOKEN', 'test-token');
143-
});
50+
### Testing
14451

145-
it('handles valid input', async () => {
146-
const { fetch, mockFetch } = setupFetch({
147-
json: async () => ({ data: 'test' })
148-
});
52+
- Use Vitest exclusively
53+
- Mock external APIs - no real network calls in tests
54+
- Use dependency injection to inject mock fetch functions
55+
- Tests mirror `src/` directory structure
14956

150-
const tool = new ExampleTool(fetch);
151-
const result = await tool.run({
152-
/* test input */
153-
});
57+
## Essential Commands
15458

155-
expect(result.type).toBe('text');
156-
expect(mockFetch).toHaveBeenCalledTimes(1);
157-
});
158-
});
59+
```bash
60+
npm install # Install dependencies
61+
npm test # Run tests
62+
npm run build # Compile TypeScript
63+
npm run lint # Check code quality (auto-fixed by pre-commit hooks)
64+
npm run inspect:build # Test with MCP inspector
65+
npx plop create-tool # Scaffold a new tool
15966
```
16067

161-
## AI Agent Collaboration Notes
68+
## Common Pitfalls to Avoid
16269

163-
### When Working with This Codebase
70+
1. **Don't patch globals** - especially `global.fetch`
71+
2. **Don't make real network calls in tests** - use mocks
72+
3. **Don't commit without tests** - new features need test coverage
73+
4. **Don't hardcode secrets** - use environment variables
74+
5. **Don't ignore type errors** - strict TypeScript is enforced
16475

165-
1. **Read Standards First:** Always consult `CLAUDE.md` for project standards
166-
2. **Use Existing Patterns:** Follow established patterns in `src/tools/` examples
167-
3. **Test-Driven Development:** Write tests alongside or before implementation
168-
4. **Policy Pipeline:** Use `fetchClient` or inject custom fetch for HTTP requests
169-
5. **Documentation:** Update relevant docs when adding features
76+
## Documentation
17077

171-
### Common Pitfalls to Avoid
78+
- **CLAUDE.md** - Detailed standards and patterns for Claude Code users
79+
- **docs/engineering_standards.md** - Complete engineering guidelines
80+
- **docs/tracing.md** - OpenTelemetry setup
81+
- **README.md** - User-facing documentation and integration guides
17282

173-
- Patching global objects (especially `fetch`)
174-
- Missing unit tests for new functionality
175-
- Hardcoding configuration values
176-
- Using JavaScript instead of TypeScript
177-
- Ignoring ESLint/Prettier warnings
178-
- Making real network calls in tests
83+
## Factual Errors to Watch For
17984

180-
### Getting Started
85+
When analyzing or modifying this codebase:
18186

182-
1. Install dependencies: `npm install`
183-
2. Run tests: `npm test`
184-
3. Check linting: `npm run lint`
185-
4. Format code: `npm run format`
186-
5. Build project: `npm run build`
187-
6. Test project: `npm run test`
87+
- The HTTP pipeline class is `HttpPipeline`, not `PolicyPipeline`
88+
- The HTTP pipeline file is `src/utils/httpPipeline.ts`, not `fetchRequest.ts`
89+
- Base tool class uses `httpRequest` parameter, not `fetch`
18890

18991
---
19092

191-
This codebase prioritizes maintainability, testability, and adherence to MCP standards. When in doubt, refer to existing tool implementations and follow established patterns.
93+
For detailed code quality standards, testing requirements, and collaboration guidelines, see docs/engineering_standards.md.

0 commit comments

Comments
 (0)