Skip to main content
Glama
omer-ayhan

Custom Context MCP Server

by omer-ayhan

text-to-json

Transform grouped text into structured JSON using customizable templates with placeholders, enabling easy data organization and integration into workflows.

Instructions

Converts groupped text from group-text-by-json tool to JSON. This tool accepts a JSON template with placeholders and groupped text from group-text-by-json tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templateYesJSON template with placeholders
textYesGroupped text from groupTextByJson tool

Implementation Reference

  • The core handler function that processes the template and text inputs, extracts key-value pairs using helper functions, constructs a prompt with the JSON result, and returns it as MCP content.
    const textToJsonTool = (template: string, text: string) => {
    	if (!template || !text) {
    		throw new Error("Both template and text are required");
    	}
    
    	try {
    		const templateObj = JSON.parse(template);
    		const templateKeys = deepObjectKeys(templateObj, true);
    
    		const jsonResult = extractKeyValuesFromText(text, templateKeys);
    
    		const resultPrompt = `
    		Print this JSON result in JSON format.
    
    		JSON result:
    		${JSON.stringify(jsonResult)}
    
    		`;
    
    		return {
    			content: [
    				{
    					type: "text",
    					text: resultPrompt,
    				},
    			],
    		};
    	} catch (error) {
    		logger.error("Error processing template:", error);
    		throw new Error(`Failed to process template: ${error}`);
    	}
    };
  • Zod schema defining the input parameters for the text-to-json tool: template (JSON template string) and text (grouped text string).
    const TextToJsonSchema = z.object({
    	template: z.string().describe("JSON template with placeholders"),
    	text: z.string().describe("Groupped text from groupTextByJson tool"),
    });
  • src/index.ts:45-49 (registration)
    Tool registration in the ListTools response, specifying name, description, and input schema derived from Zod schema.
    {
    	name: TOOL_NAMES.textToJson,
    	description: `Converts groupped text from ${TOOL_NAMES.groupTextByJson} tool to JSON. This tool accepts a JSON template with placeholders and groupped text from ${TOOL_NAMES.groupTextByJson} tool.`,
    	inputSchema: zodToJsonSchema(TextToJsonSchema),
    },
  • Dispatcher case in the CallTool request handler that validates args and invokes the textToJsonTool handler.
    case TOOL_NAMES.textToJson:
    	const textToJsonArgs = args as TextToJsonSchemaType;
    	return textToJsonTool(textToJsonArgs.template, textToJsonArgs.text);
  • Constant defining the tool name 'text-to-json' used in registration and dispatching.
    textToJson: "text-to-json",
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the conversion process but lacks details on error handling, output format, or any constraints (e.g., template syntax, validation rules). For a tool with no annotations, this leaves significant gaps in understanding how it behaves beyond the basic operation.

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

Conciseness4/5

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

The description is concise with two sentences that directly state the tool's function and inputs. It avoids unnecessary words and is front-loaded with the core purpose. However, the repetition of 'group-text-by-json tool' could be slightly streamlined, and it lacks structural elements like bullet points for clarity.

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

Completeness3/5

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

Given the tool's complexity (data transformation with two parameters), lack of annotations, and no output schema, the description is incomplete. It covers the basic operation but misses details on output format, error cases, or example usage. While it mentions the sibling tool, more context on the overall workflow would improve completeness for effective agent use.

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?

Schema description coverage is 100%, so the schema already documents both parameters ('template' and 'text') with clear descriptions. The description adds minimal value by repeating that it accepts a 'JSON template with placeholders' and 'groupped text from groupTextByJson tool', but doesn't provide additional semantics beyond what the schema states. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the tool's purpose: converting grouped text to JSON using a template. It specifies the verb 'converts' and the resource 'groupped text from group-text-by-json tool', making the action and input source explicit. However, it doesn't fully distinguish from its sibling 'group-text-by-json' beyond mentioning it as the source, missing an opportunity to clarify the workflow relationship more distinctly.

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

Usage Guidelines3/5

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

The description implies usage by specifying that it accepts input from 'group-text-by-json tool', suggesting a sequential workflow. However, it lacks explicit guidance on when to use this tool versus alternatives (e.g., direct JSON creation tools) or any prerequisites beyond having the grouped text. No exclusions or clear when-not-to-use scenarios are provided.

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

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/omer-ayhan/custom-context-mcp'

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