Skip to main content
Glama
ukicar

Gallica/BnF MCP Server

by ukicar

natural_language_search

Search the Gallica digital library using natural language queries to find documents across all fields including titles, authors, subjects, and dates.

Instructions

Search the Gallica digital library using natural language. This is a simplified search that uses the "gallica all" operator to search across all fields.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language search query
max_resultsNoMaximum number of results to return (1-50)
start_recordNoStarting record for pagination

Implementation Reference

  • Main tool handler - createNaturalLanguageSearchTool function defines the 'natural_language_search' MCP tool with its name, description, inputSchema, and async handler that calls searchApi.naturalLanguageSearch().
    export function createNaturalLanguageSearchTool(searchApi: SearchAPI) {
      return {
        name: 'natural_language_search',
        description: 'Search the Gallica digital library using natural language. This is a simplified search that uses the "gallica all" operator to search across all fields.',
        inputSchema: {
          type: 'object',
          properties: {
            query: {
              type: 'string',
              description: 'Natural language search query',
            },
            max_results: {
              type: 'number',
              description: 'Maximum number of results to return (1-50)',
              default: config.defaultMaxRecords,
            },
            start_record: {
              type: 'number',
              description: 'Starting record for pagination',
              default: config.defaultStartRecord,
            },
          },
          required: ['query'],
        },
        handler: async (args: unknown) => {
          const parsed = searchParamsSchema.extend({ query: z.string() }).parse(args);
          return await searchApi.naturalLanguageSearch(
            parsed.query,
            parsed.max_results ?? config.defaultMaxRecords,
            parsed.start_record ?? config.defaultStartRecord
          );
        },
      };
  • Core search logic - naturalLanguageSearch method formats the query as 'gallica all "{query}"' and delegates to the base search method.
    naturalLanguageSearch(
      query: string,
      maxResults: number = config.defaultMaxRecords,
      startRecord: number = config.defaultStartRecord
    ): Promise<SearchResult> {
      const formattedQuery = `gallica all "${query}"`;
      return this.search(formattedQuery, startRecord, maxResults);
    }
  • Zod schema definition for search parameters (max_results and start_record) used for input validation in the handler.
    const searchParamsSchema = z.object({
      max_results: z.number().int().positive().max(50).optional(),
      start_record: z.number().int().positive().optional(),
    });
  • Tool registration - creates the naturalLanguageSearch tool instance and adds it to the tools array that is registered with the MCP server.
    const naturalLanguageSearch = createNaturalLanguageSearchTool(searchApi);
    
    // Register extended item tools (4 new tools)
    const getItemDetails = createGetItemDetailsTool(itemsClient);
    const getItemPages = createGetItemPagesTool(itemsClient);
    const getPageImage = createGetPageImageTool(iiifClient);
    const getPageText = createGetPageTextTool(textClient);
    
    // Register sequential reporting tool
    const sequentialReporting = createSequentialReportingTool(reportingServer);
    
    // Register all tools with error handling
    const tools = [
      searchByTitle,
      searchByAuthor,
      searchBySubject,
      searchByDate,
      searchByDocumentType,
      advancedSearch,
      naturalLanguageSearch,
      getItemDetails,
      getItemPages,
      getPageImage,
      getPageText,
      sequentialReporting,
    ];
  • CallTool handler registration - handles incoming tool call requests, finds the tool by name (e.g., 'natural_language_search'), and executes its handler.
    server.setRequestHandler(
      CallToolRequestSchema,
      async (request) => {
        logger.info(`[TOOL] Tool call requested: ${request.params.name}`);
        logger.info(`[TOOL] Tool arguments: ${JSON.stringify(request.params.arguments, null, 2)}`);
        
        const tool = tools.find((t) => t.name === request.params.name);
        if (!tool) {
          logger.error(`[TOOL] Tool not found: ${request.params.name || 'unknown'}`);
          logger.info(`[TOOL] Available tools: ${tools.map(t => t.name).join(', ')}`);
          throw new Error(`Tool not found: ${request.params.name || 'unknown'}`);
        }
    
        try {
          logger.info(`[TOOL] Executing tool: ${tool.name}`);
          logger.debug(`[TOOL] Tool handler called with arguments:`, request.params.arguments);
          const result = await tool.handler(request.params.arguments);
          logger.info(`[TOOL] Tool ${tool.name} completed successfully`);
          const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
          logger.debug(`[TOOL] Tool result type: ${typeof result}, length: ${resultStr.length}`);
          
          const response = {
            content: [
              {

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/ukicar/sweet-bnf'

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