Thank you for your interest in contributing to the IBGE MCP Server! This document provides guidelines and information for contributors.
- Code of Conduct
- Getting Started
- Development Setup
- Project Structure
- Adding New Tools
- Testing
- Code Style
- Submitting Changes
Please be respectful and constructive in all interactions. We welcome contributors of all experience levels.
- Fork the repository
- Clone your fork:
git clone https://github.com/YOUR-USERNAME/ibge-br-mcp.git - Create a feature branch:
git checkout -b feature/your-feature-name - Make your changes
- Submit a pull request
- Node.js 18.0.0 or higher
- npm
cd ibge-br-mcp
npm install| Command | Description |
|---|---|
npm run build |
Compile TypeScript to JavaScript |
npm run watch |
Watch mode for development |
npm run dev |
Build and run the server |
npm run lint |
Run ESLint |
npm run lint:fix |
Run ESLint with auto-fix |
npm run format |
Format code with Prettier |
npm run format:check |
Check formatting |
npm test |
Run tests |
npm run test:watch |
Run tests in watch mode |
npm run test:coverage |
Run tests with coverage report |
npm run inspector |
Open MCP Inspector |
ibge-br-mcp/
├── src/
│ ├── index.ts # Main MCP server and tool registration
│ ├── types.ts # TypeScript type definitions
│ ├── cache.ts # In-memory caching system
│ ├── metrics.ts # Performance metrics tracking
│ ├── errors.ts # Error handling utilities
│ ├── validation.ts # Input validation functions
│ ├── retry.ts # Retry mechanism for network calls
│ ├── config.ts # Configuration and constants
│ ├── tools/ # Individual tool implementations
│ │ ├── estados.ts
│ │ ├── municipios.ts
│ │ ├── sidra.ts
│ │ └── ...
│ └── utils/ # Utility functions
│ ├── formatters.ts
│ └── index.ts
├── tests/ # Test files
│ ├── validation.test.ts
│ ├── cache.test.ts
│ └── ...
├── dist/ # Compiled JavaScript (generated)
└── package.json
Create a new file in src/tools/ with the following structure:
import { z } from "zod";
import { IBGE_API } from "../types.js";
import { cacheKey, CACHE_TTL, cachedFetch } from "../cache.js";
import { withMetrics } from "../metrics.js";
import { createMarkdownTable } from "../utils/index.js";
import { parseHttpError, ValidationErrors } from "../errors.js";
// Define the input schema using Zod
export const myToolSchema = z.object({
param1: z.string().describe("Description of param1"),
param2: z.number().optional().default(10).describe("Description of param2"),
});
export type MyToolInput = z.infer<typeof myToolSchema>;
// Implement the tool function
export async function myTool(input: MyToolInput): Promise<string> {
return withMetrics("my_tool", "api_category", async () => {
try {
// Your implementation here
const url = `${IBGE_API.LOCALIDADES}/...`;
const key = cacheKey(url);
const data = await cachedFetch<YourType>(url, key, CACHE_TTL.MEDIUM);
// Format and return results
return formatResults(data);
} catch (error) {
if (error instanceof Error) {
return parseHttpError(error, "my_tool", { param1: input.param1 });
}
return ValidationErrors.emptyResult("my_tool");
}
});
}
// Export tool definition
export const myToolTool = {
name: "my_tool",
description: `Description of your tool in English.
Features:
- Feature 1
- Feature 2
Examples:
- Example usage 1
- Example usage 2`,
inputSchema: myToolSchema,
handler: myTool,
};Add your export to src/tools/index.ts:
export * from "./my-tool.js";Register the tool in src/index.ts:
import { myToolSchema, myTool } from "./tools/my-tool.js";
// In the tools section:
server.tool(
"my_tool",
`Tool description in English...`,
myToolSchema.shape,
async (args) => {
const result = await myTool(args);
return { content: [{ type: "text", text: result }] };
}
);Create a test file tests/my-tool.test.ts:
import { describe, it, expect } from "vitest";
import { myToolSchema } from "../src/tools/my-tool.js";
describe("myToolSchema", () => {
it("should accept valid input", () => {
const result = myToolSchema.safeParse({ param1: "value" });
expect(result.success).toBe(true);
});
// Add more tests...
});# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage- Place test files in the
tests/directory - Name test files with
.test.tssuffix - Use descriptive test names
- Test both valid and invalid inputs
- Mock external API calls for integration tests
The project uses ESLint and Prettier for code quality:
# Check for linting issues
npm run lint
# Auto-fix linting issues
npm run lint:fix
# Format code
npm run format- Use TypeScript for all code
- Use ES modules (
.jsextension in imports) - Prefer
constoverlet - Use descriptive variable and function names
- Add JSDoc comments for public functions
- Keep functions focused and small
- Use centralized utilities instead of inline implementations
- Write tool descriptions in English
- Include a brief summary
- List key features
- Provide usage examples
- Be concise but informative
- Ensure all tests pass:
npm test - Ensure no linting errors:
npm run lint - Update documentation if needed
- Add entries to CHANGELOG.md
- Create a pull request with a clear description
Use clear, descriptive commit messages:
Add new tool for X functionality
- Implement X feature
- Add tests for X
- Update documentation
- All changes require review before merging
- Address review feedback promptly
- Keep discussions constructive
If you have questions, please:
- Check existing issues
- Read the documentation
- Open a new issue with your question
Thank you for contributing!