Skip to main content
Glama

get_character_by_id

Retrieve detailed Marvel character information using a unique character ID through the Marvel MCP server. Query specific characters for integration into applications or data analysis.

Instructions

Fetch a Marvel character by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
characterIdYes

Implementation Reference

  • The tool handler that parses the input arguments using GetCharacterByIdSchema, fetches the character data from the Marvel API using httpRequest, and parses the response using CharacterDataWrapperSchema.
    handler: async (args: any) => { const argsParsed = GetCharacterByIdSchema.parse(args); const res = await httpRequest(`/characters/${argsParsed.characterId}`); return CharacterDataWrapperSchema.parse(res); }
  • Registers the 'get_character_by_id' tool with its description, input schema, and handler function.
    export const get_character_by_id = { description: `Fetch a Marvel character by ID.`, schema: GetCharacterByIdSchema, handler: async (args: any) => { const argsParsed = GetCharacterByIdSchema.parse(args); const res = await httpRequest(`/characters/${argsParsed.characterId}`); return CharacterDataWrapperSchema.parse(res); } };
  • Zod schema used to parse and validate the response from the Marvel Characters API endpoint.
    export const CharacterDataWrapperSchema = z.object({ code: z.number(), status: z.string(), copyright: z.string(), attributionText: z.string(), attributionHTML: z.string(), data: CharacterDataContainerSchema, etag: z.string(), });
  • Helper utility function that makes authenticated HTTP requests to the Marvel API, handling timestamp, API key, and hash authentication.
    export async function httpRequest(endpoint: string, params: Record<string, string | number | undefined> = {}) { const url = new URL(`${MARVEL_API_BASE}${endpoint}`); const authParams = createAuthParams(); url.searchParams.set('ts', authParams.ts); url.searchParams.set('apikey', authParams.apikey); url.searchParams.set('hash', authParams.hash); for (const [key, value] of Object.entries(params)) { if (value !== undefined) { url.searchParams.set(key, String(value)); } } const res = await fetch(url.toString()); if (!res.ok) { const text = await res.text(); throw new Error(`Marvel API error: ${res.status} - ${text}`); } return res.json(); }

Other Tools

Related 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/DanWahlin/marvel-mcp'

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