Skip to main content
Glama
ukicar

Gallica/BnF MCP Server

by ukicar

search_by_subject

Find documents in the Gallica digital library by searching for specific subjects, with options for exact matches and pagination controls.

Instructions

Search for documents in the Gallica digital library by subject.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
subjectYesThe subject to search for
exact_matchNoIf true, search for the exact subject; otherwise, search for subject containing the words
max_resultsNoMaximum number of results to return (1-50)
start_recordNoStarting record for pagination

Implementation Reference

  • The main tool handler and registration for search_by_subject. Creates the tool with name, description, input schema, and async handler function that parses arguments and calls the SearchAPI.searchBySubject method.
    export function createSearchBySubjectTool(searchApi: SearchAPI) {
      return {
        name: 'search_by_subject',
        description: 'Search for documents in the Gallica digital library by subject.',
        inputSchema: {
          type: 'object',
          properties: {
            subject: {
              type: 'string',
              description: 'The subject to search for',
            },
            exact_match: {
              type: 'boolean',
              description: 'If true, search for the exact subject; otherwise, search for subject containing the words',
              default: false,
            },
            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: ['subject'],
        },
        handler: async (args: unknown) => {
          const parsed = exactMatchSchema.extend({ subject: z.string() }).parse(args);
          return await searchApi.searchBySubject(
            parsed.subject,
            parsed.exact_match ?? false,
            parsed.max_results ?? config.defaultMaxRecords,
            parsed.start_record ?? config.defaultStartRecord
          );
        },
      };
  • The actual implementation of searchBySubject method in the SearchAPI class. Constructs the SRU query using 'dc.subject' field with optional exact matching, then delegates to the core search method.
    searchBySubject(
      subject: string,
      exactMatch: boolean = false,
      maxResults: number = config.defaultMaxRecords,
      startRecord: number = config.defaultStartRecord
    ): Promise<SearchResult> {
      const query = exactMatch ? `dc.subject all "${subject}"` : `dc.subject all ${subject}`;
      return this.search(query, startRecord, maxResults);
    }
  • Schema definitions used by search_by_subject. Defines searchParamsSchema (max_results, start_record) and exactMatchSchema which extends it with exact_match boolean field.
    const searchParamsSchema = z.object({
      max_results: z.number().int().positive().max(50).optional(),
      start_record: z.number().int().positive().optional(),
    });
    
    const exactMatchSchema = searchParamsSchema.extend({
      exact_match: z.boolean().optional(),
    });
  • src/mcpServer.ts:20-20 (registration)
    Import statement for createSearchBySubjectTool function from tools/gallicaSearch.js.
    createSearchBySubjectTool,
  • src/mcpServer.ts:78-97 (registration)
    Tool instantiation and registration. Creates the searchBySubject tool instance on line 78 and adds it to the tools array on line 97 for MCP server registration.
    const searchBySubject = createSearchBySubjectTool(searchApi);
    const searchByDate = createSearchByDateTool(searchApi);
    const searchByDocumentType = createSearchByDocumentTypeTool(searchApi);
    const advancedSearch = createAdvancedSearchTool(searchApi);
    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,

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