Skip to main content
Glama

get_context

Retrieve a Markdown element with surrounding content for contextual editing in structured documents.

Instructions

Returns the target element along with its immediate neighbors (before and after).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
pathYesPath to the element (e.g., 'Intro > paragraph 1')

Implementation Reference

  • Core implementation of get_context: locates the target element using find_by_path and constructs a context dictionary with the current element and its immediate before/after siblings.
    def get_context(self, path: str) -> Dict[str, Any]: """Get element and its neighbors""" target = self.find_by_path(path) if not target: return {"error": "Not found"} siblings = target.parent.children if target.parent else self.elements idx = siblings.index(target) context = { "current": {"path": target.path, "content": target.content}, "before": None, "after": None } if idx > 0: context["before"] = {"path": siblings[idx-1].path, "content": siblings[idx-1].content[:200]} if idx < len(siblings) - 1: context["after"] = {"path": siblings[idx+1].path, "content": siblings[idx+1].content[:200]} return context
  • Input/output schema definition for the 'get_context' tool, specifying parameters file_path and path, and returning target, before, after objects.
    inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "examples": ["./document.md"] }, "path": { "type": "string", "description": "Path to the element (e.g., 'Intro > paragraph 1')", "examples": ["Introduction > paragraph 2", "Conclusion"] } }, "required": ["file_path", "path"], "additionalProperties": False }, outputSchema={ "type": "object", "properties": { "target": {"type": "object", "description": "The target element"}, "before": {"type": "object", "description": "Element before target"}, "after": {"type": "object", "description": "Element after target"} } }
  • Registration of the 'get_context' tool in the MCP server's list_tools() function, including name, title, description, and schemas.
    Tool( name="get_context", title="Get Element Context", description="Returns the target element along with its immediate neighbors (before and after).", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "examples": ["./document.md"] }, "path": { "type": "string", "description": "Path to the element (e.g., 'Intro > paragraph 1')", "examples": ["Introduction > paragraph 2", "Conclusion"] } }, "required": ["file_path", "path"], "additionalProperties": False }, outputSchema={ "type": "object", "properties": { "target": {"type": "object", "description": "The target element"}, "before": {"type": "object", "description": "Element before target"}, "after": {"type": "object", "description": "Element after target"} } } ),
  • Dispatch handler in call_tool that routes 'get_context' calls to the get_element_context function from edit_tools.
    elif name == "get_context": res = await get_element_context(file_path, arguments["path"]) return {"content": [TextContent(type="text", text="Context extracted")], "structuredContent": res, "isError": "error" in res}
  • Top-level async wrapper that delegates to EditTool instance's get_context method.
    async def get_element_context(file_path: str, path: str): return await _instance.get_context(file_path, path)

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/KazKozDev/markdown-editor-mcp-server'

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