From 6ff7c12c08473b367ddf5c968309d0b7fb7db114 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 30 Mar 2026 20:01:41 -0500 Subject: [PATCH] Strip base64 images from get_knowledge_article response --- server/odoo_mcp.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/server/odoo_mcp.py b/server/odoo_mcp.py index 71cbc31..3dc9ccb 100644 --- a/server/odoo_mcp.py +++ b/server/odoo_mcp.py @@ -7,6 +7,7 @@ Purchase, Inventory, and Employees. """ import os +import re import xmlrpc.client from typing import Optional from mcp.server.fastmcp import FastMCP @@ -124,11 +125,22 @@ def search_knowledge_articles(query: str = "", limit: int = 20) -> list: @mcp.tool() def get_knowledge_article(article_id: int) -> dict: - """Get the full content of a Knowledge article by ID.""" + """Get the full content of a Knowledge article by ID. + Note: Inline base64 images are replaced with [embedded image] placeholders + to keep the response size manageable.""" r = _read("knowledge.article", [article_id], ["id", "name", "body", "parent_id", "child_ids", "is_published", "write_date", "write_uid"]) - return r[0] if r else {} + if not r: + return {} + article = r[0] + if article.get("body"): + article["body"] = re.sub( + r'src="data:image/[^;]+;base64,[A-Za-z0-9+/=]+"', + 'src="[embedded image]"', + article["body"] + ) + return article @mcp.tool() def create_knowledge_article(name: str, body: str, parent_id: int = None) -> int: @@ -576,12 +588,4 @@ def odoo_get_record(model: str, record_id: int) -> dict: if __name__ == "__main__": - transport = os.environ.get("MCP_TRANSPORT", "stdio") - if transport == "http": - mcp.run( - transport="streamable-http", - host=os.environ.get("MCP_HOST", "0.0.0.0"), - port=int(os.environ.get("MCP_PORT", "8080")), - ) - else: - mcp.run() + mcp.run()