Skip to main content
Glama
julienkalamon

IGN API Carto MCP Server

Get communes by postal code

ign_get_communes_by_postal_code
Read-onlyIdempotent

Find all French municipalities associated with a specific postal code. This tool queries IGN geographic data to return communes sharing the same postal code.

Instructions

Retrieve French communes (municipalities) associated with a postal code.

This tool queries the IGN API Carto codes-postaux module to find all communes that share a given postal code. In France, a postal code can cover multiple communes, and this tool returns all of them.

Args:

  • code_postal (string): French postal code (5 digits, e.g. "75001", "69000")

  • response_format ('markdown' | 'json'): Output format (default: 'markdown')

Returns: For JSON format: [ { "codePostal": "75001", "codeCommune": "75101", "nomCommune": "Paris 1er Arrondissement", "libelleAcheminement": "PARIS" } ]

Examples:

  • "What communes are in postal code 75001?" -> code_postal="75001"

  • "Find cities for zip 69000" -> code_postal="69000"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
code_postalYesFrench postal code (5 digits)
response_formatNoOutput format: 'markdown' for human-readable or 'json' for machine-readablemarkdown

Implementation Reference

  • src/index.ts:59-113 (registration)
    Registration of the 'ign_get_communes_by_postal_code' tool with title, description, inputSchema, annotations, and handler function.
    server.registerTool(
      "ign_get_communes_by_postal_code",
      {
        title: "Get communes by postal code",
        description: `Retrieve French communes (municipalities) associated with a postal code.
    
    This tool queries the IGN API Carto codes-postaux module to find all communes that share a given postal code. In France, a postal code can cover multiple communes, and this tool returns all of them.
    
    Args:
      - code_postal (string): French postal code (5 digits, e.g. "75001", "69000")
      - response_format ('markdown' | 'json'): Output format (default: 'markdown')
    
    Returns:
      For JSON format:
      [
        {
          "codePostal": "75001",
          "codeCommune": "75101",
          "nomCommune": "Paris 1er Arrondissement",
          "libelleAcheminement": "PARIS"
        }
      ]
    
    Examples:
      - "What communes are in postal code 75001?" -> code_postal="75001"
      - "Find cities for zip 69000" -> code_postal="69000"`,
        inputSchema: z.object({
          code_postal: z
            .string()
            .regex(/^\d{5}$/, "Postal code must be 5 digits")
            .describe("French postal code (5 digits)"),
          response_format: ResponseFormatSchema,
        }).strict(),
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: true,
        },
      },
      async ({ code_postal, response_format }) => {
        const communes = await getCommunesByPostalCode(code_postal);
    
        if (response_format === ResponseFormat.JSON) {
          return {
            content: [{ type: "text", text: JSON.stringify(communes, null, 2) }],
          };
        }
    
        const markdown = formatCommunesToMarkdown(communes, code_postal);
        return {
          content: [{ type: "text", text: truncateResponse(markdown, CHARACTER_LIMIT) }],
        };
      }
    );
  • Handler implementation: fetches communes via getCommunesByPostalCode, returns JSON or formatted markdown response.
      const communes = await getCommunesByPostalCode(code_postal);
    
      if (response_format === ResponseFormat.JSON) {
        return {
          content: [{ type: "text", text: JSON.stringify(communes, null, 2) }],
        };
      }
    
      const markdown = formatCommunesToMarkdown(communes, code_postal);
      return {
        content: [{ type: "text", text: truncateResponse(markdown, CHARACTER_LIMIT) }],
      };
    }
  • Zod inputSchema: validates code_postal (5-digit string) and response_format.
    inputSchema: z.object({
      code_postal: z
        .string()
        .regex(/^\d{5}$/, "Postal code must be 5 digits")
        .describe("French postal code (5 digits)"),
      response_format: ResponseFormatSchema,
    }).strict(),
  • getCommunesByPostalCode: core API client function querying IGN endpoint `/codes-postaux/communes/${code_postal}`.
    export async function getCommunesByPostalCode(codePostal: string): Promise<CommuneResponse[]> {
      return apiRequest<CommuneResponse[]>(`/codes-postaux/communes/${codePostal}`);
    }
  • CommuneResponse TypeScript interface defining the structure of commune data returned by the API.
    export interface CommuneResponse {
      codePostal: string;
      codeCommune: string;
      nomCommune: string;
      libelleAcheminement: string;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, destructiveHint=false, openWorldHint=true, and idempotentHint=true. The description adds valuable context beyond annotations: it specifies the API source (IGN API Carto codes-postaux module), explains the French postal code system behavior, and describes the return format options. No contradiction with annotations exists.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It starts with a clear purpose statement, adds necessary context about the French postal system, then provides structured sections for Args, Returns, and Examples. Every sentence adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only query tool with comprehensive annotations and 100% schema coverage, the description provides excellent completeness. It explains the tool's purpose, source API, French postal code nuance, parameter usage with examples, and return format details. The lack of an output schema is compensated by the detailed Returns section showing the JSON structure.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the schema already fully documents both parameters (code_postal pattern and response_format enum with defaults). The description adds minimal value beyond the schema: it provides example postal codes ('75001', '69000') and clarifies that response_format controls output format. This meets the baseline 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Retrieve French communes associated with a postal code'), identifies the resource ('communes/municipalities'), and distinguishes from siblings by specifying it queries the 'Carto codes-postaux module' for postal code to commune mapping. It explicitly mentions the French context where one postal code can cover multiple communes, which differentiates it from tools like administrative limits or cadastre queries.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool: for finding all communes that share a given French postal code. It explains the French postal system nuance (one code can cover multiple communes). However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools for different types of geographic queries.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/julienkalamon/ign-apicarto-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server