TypeScript SDK and MCP (Model Context Protocol) server for the eCFR (Electronic Code of Federal Regulations) API.
- 🚀 TypeScript SDK - Fully typed client for all eCFR API endpoints
- 🤖 MCP Server - AI-ready server for integration with Claude and other AI assistants
- 🔄 Auto-generated - Automatically updated from the official eCFR OpenAPI specification
- 📦 Modern tooling - Built with Bun, Biome, and Orval
- 🐳 Docker support - Ready-to-use Docker image for the MCP server
- ✨ Tree-shakeable - Only import what you need
- 🔍 Type-safe - Full TypeScript support with auto-completion
# npm
npm install @beshkenadze/ecfr-sdk
# yarn
yarn add @beshkenadze/ecfr-sdk
# pnpm
pnpm add @beshkenadze/ecfr-sdk
# bun
bun add @beshkenadze/ecfr-sdkFirst, authenticate with GitHub Packages:
# Create a .npmrc file in your project root
echo "@beshkenadze:registry=https://npm.pkg.github.com" >> .npmrc
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> .npmrcThen install:
npm install @beshkenadze/ecfr-sdkimport { ecfrClient } from '@beshkenadze/ecfr-sdk';
// Get all agencies
const agencies = await ecfrClient.getApiAdminV1AgenciesJson();
console.log(agencies.agencies);
// Search regulations
const searchResults = await ecfrClient.getApiSearchV1Results({
query: 'environmental protection',
per_page: 20,
page: 1,
});
console.log(`Found ${searchResults.count} results`);
// Get title structure
const titleStructure = await ecfrClient.getApiVersionerV1StructureDateTitleTitleJson({
date: '2024-01-01',
title: '40', // Environmental Protection
});
// Get corrections for a specific title
const corrections = await ecfrClient.getApiAdminV1CorrectionsTitleTitleJson({
title: '40',
});
// Search with filters
const filteredSearch = await ecfrClient.getApiSearchV1Results({
query: 'carbon emissions',
title: ['40'], // Only Title 40
last_modified_on_or_after: '2024-01-01',
per_page: 50,
});
// Get ancestry information
const ancestry = await ecfrClient.getApiVersionerV1AncestryDateTitleTitleJson({
date: '2024-01-01',
title: '40',
part: '60',
section: '60.1',
});
// Get search suggestions
const suggestions = await ecfrClient.getApiSearchV1Suggestions({
query: 'clean air',
title: ['40', '42'],
});import { ecfrClient } from '@beshkenadze/ecfr-sdk';
try {
const result = await ecfrClient.getApiSearchV1Results({
query: 'test',
});
} catch (error) {
if (error.response?.status === 404) {
console.error('Resource not found');
} else if (error.response?.status === 400) {
console.error('Bad request:', error.response.data);
} else {
console.error('API error:', error.message);
}
}import { createEcfrClient } from '@beshkenadze/ecfr-sdk';
// Create a custom client with your own Axios config
const client = createEcfrClient({
baseURL: 'https://www.ecfr.gov',
timeout: 30000,
headers: {
'User-Agent': 'MyApp/1.0',
},
});
const results = await client.getApiSearchV1Results({ query: 'test' });The MCP server allows AI assistants to interact with the eCFR API.
docker run -i --rm beshkenadze/ecfr-mcp-server:latest# Clone the repository
git clone https://github.com/beshkenadze/ecfr-sdk.git
cd ecfr-sdk
# Install dependencies
bun install
# Run the MCP server
bun run mcp:serverAdd to your Claude Desktop configuration:
{
"mcpServers": {
"ecfr": {
"command": "docker",
"args": ["run", "-i", "--rm", "beshkenadze/ecfr-mcp-server:latest"],
"disabled": false
}
}
}Or run locally:
{
"mcpServers": {
"ecfr": {
"command": "bunx",
"args": ["@beshkenadze/ecfr-sdk", "mcp"],
"disabled": false
}
}
}GET /api/admin/v1/agencies.json- Get all agenciesGET /api/admin/v1/corrections.json- Get eCFR correctionsGET /api/admin/v1/corrections/title/{title}.json- Get corrections by title
GET /api/search/v1/results- Search regulationsGET /api/search/v1/count- Get search result countGET /api/search/v1/summary- Get search summaryGET /api/search/v1/counts/daily- Get daily countsGET /api/search/v1/counts/titles- Get counts by titleGET /api/search/v1/counts/hierarchy- Get counts by hierarchyGET /api/search/v1/suggestions- Get search suggestions
GET /api/versioner/v1/ancestry/{date}/title-{title}.json- Get ancestryGET /api/versioner/v1/full/{date}/title-{title}.xml- Get full XMLGET /api/versioner/v1/structure/{date}/title-{title}.json- Get structureGET /api/versioner/v1/titles.json- Get all titlesGET /api/versioner/v1/versions/title-{title}.json- Get versions
- Bun >= 1.0
- Node.js >= 18 (for compatibility)
- Docker (optional, for MCP server)
# Clone the repository
git clone https://github.com/beshkenadze/ecfr-sdk.git
cd ecfr-sdk
# Install dependencies
bun install
# Generate SDK from OpenAPI spec
bun run generate
# Run tests
bun test
# Build the package
bun run buildbun run dev- Run development serverbun run build- Build the SDKbun run generate- Regenerate SDK from OpenAPI specbun run format- Format code with Biomebun run lint- Lint code with Biomebun run check- Run all checksbun run test- Run testsbun run test:watch- Run tests in watch modebun run test:integration- Run integration testsbun run test:e2e- Run end-to-end testsbun run mcp:server- Run MCP server locallybun run docker:build- Build Docker imagebun run docker:run- Run Docker container
ecfr-sdk/
├── src/
│ ├── api/ # SDK implementation
│ │ ├── client.ts # Axios client configuration
│ │ └── generated/ # Auto-generated API clients
│ ├── mcp/ # MCP server implementation
│ │ └── server.ts # MCP server entry point
│ └── index.ts # Main SDK exports
├── scripts/ # Build and generation scripts
├── tests/ # Test files
└── docs/ # API documentation
# Run all tests
bun test
# Run specific test file
bun test src/api/client.test.ts
# Run tests in watch mode
bun test --watch
# Run integration tests
SKIP_INTEGRATION_TESTS=false bun test src
# Run e2e tests
SKIP_E2E_TESTS=false bun test tests/e2eContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Write tests for new features
- Update documentation as needed
- Follow the existing code style
- Run
bun run checkbefore committing
This project uses semantic versioning. To release a new version:
# Patch release (1.0.0 -> 1.0.1)
bun version patch
# Minor release (1.0.0 -> 1.1.0)
bun version minor
# Major release (1.0.0 -> 2.0.0)
bun version majorThis will automatically:
- Update the version in package.json
- Build the project
- Create a git commit and tag
- Push to GitHub
- Trigger the release workflow
This project is licensed under the MIT License - see the LICENSE file for details.
- eCFR API - Official eCFR API
- Orval - OpenAPI client generator
- Model Context Protocol - MCP specification
- Bun - JavaScript runtime & toolkit