Strip base64 images from get_knowledge_article response
This commit is contained in:
+15
-11
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user