Skip to content

Commit 962f864

Browse files
phernandezclaude
andcommitted
feat: instrument remaining MCP tools with telemetry
Add track_mcp_tool() calls to all remaining MCP tools: - view_note - list_directory - move_note - read_content - canvas - list_memory_projects - create_memory_project - delete_project - search (ChatGPT) - fetch (ChatGPT) This completes telemetry instrumentation for all 17 MCP tools. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 2b51424 commit 962f864

7 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/basic_memory/mcp/tools/canvas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from basic_memory.mcp.project_context import get_active_project
1414
from basic_memory.mcp.server import mcp
1515
from basic_memory.mcp.tools.utils import call_put, call_post, resolve_entity_id
16+
from basic_memory.telemetry import track_mcp_tool
1617

1718

1819
@mcp.tool(
@@ -94,6 +95,7 @@ async def canvas(
9495
Raises:
9596
ToolError: If project doesn't exist or folder path is invalid
9697
"""
98+
track_mcp_tool("canvas")
9799
async with get_client() as client:
98100
active_project = await get_active_project(client, project, context)
99101

src/basic_memory/mcp/tools/chatgpt_tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from basic_memory.mcp.tools.read_note import read_note
1616
from basic_memory.schemas.search import SearchResponse
1717
from basic_memory.config import ConfigManager
18+
from basic_memory.telemetry import track_mcp_tool
1819

1920

2021
def _format_search_results_for_chatgpt(results: SearchResponse) -> List[Dict[str, Any]]:
@@ -88,6 +89,7 @@ async def search(
8889
List with one dict: `{ "type": "text", "text": "{...JSON...}" }`
8990
where the JSON body contains `results`, `total_count`, and echo of `query`.
9091
"""
92+
track_mcp_tool("search")
9193
logger.info(f"ChatGPT search request: query='{query}'")
9294

9395
try:
@@ -151,6 +153,7 @@ async def fetch(
151153
List with one dict: `{ "type": "text", "text": "{...JSON...}" }`
152154
where the JSON body includes `id`, `title`, `text`, `url`, and metadata.
153155
"""
156+
track_mcp_tool("fetch")
154157
logger.info(f"ChatGPT fetch request: id='{id}'")
155158

156159
try:

src/basic_memory/mcp/tools/list_directory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from basic_memory.mcp.project_context import get_active_project
1010
from basic_memory.mcp.server import mcp
1111
from basic_memory.mcp.tools.utils import call_get
12+
from basic_memory.telemetry import track_mcp_tool
1213

1314

1415
@mcp.tool(
@@ -63,6 +64,7 @@ async def list_directory(
6364
Raises:
6465
ToolError: If project doesn't exist or directory path is invalid
6566
"""
67+
track_mcp_tool("list_directory")
6668
async with get_client() as client:
6769
active_project = await get_active_project(client, project, context)
6870

src/basic_memory/mcp/tools/move_note.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from basic_memory.mcp.project_context import get_active_project
1313
from basic_memory.schemas import EntityResponse
1414
from basic_memory.schemas.project_info import ProjectList
15+
from basic_memory.telemetry import track_mcp_tool
1516
from basic_memory.utils import validate_project_path
1617

1718

@@ -395,6 +396,7 @@ async def move_note(
395396
- Re-indexes the entity for search
396397
- Maintains all observations and relations
397398
"""
399+
track_mcp_tool("move_note")
398400
async with get_client() as client:
399401
logger.debug(f"Moving note: {identifier} to {destination_path} in project: {project}")
400402

src/basic_memory/mcp/tools/project_management.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
ProjectStatusResponse,
1616
ProjectInfoRequest,
1717
)
18+
from basic_memory.telemetry import track_mcp_tool
1819
from basic_memory.utils import generate_permalink
1920

2021

@@ -40,6 +41,7 @@ async def list_memory_projects(context: Context | None = None) -> str:
4041
Example:
4142
list_memory_projects()
4243
"""
44+
track_mcp_tool("list_memory_projects")
4345
async with get_client() as client:
4446
if context: # pragma: no cover
4547
await context.info("Listing all available projects")
@@ -92,6 +94,7 @@ async def create_memory_project(
9294
create_memory_project("my-research", "~/Documents/research")
9395
create_memory_project("work-notes", "/home/user/work", set_default=True)
9496
"""
97+
track_mcp_tool("create_memory_project")
9598
async with get_client() as client:
9699
# Check if server is constrained to a specific project
97100
constrained_project = os.environ.get("BASIC_MEMORY_MCP_PROJECT")
@@ -147,6 +150,7 @@ async def delete_project(project_name: str, context: Context | None = None) -> s
147150
This action cannot be undone. The project will need to be re-added
148151
to access its content through Basic Memory again.
149152
"""
153+
track_mcp_tool("delete_project")
150154
async with get_client() as client:
151155
# Check if server is constrained to a specific project
152156
constrained_project = os.environ.get("BASIC_MEMORY_MCP_PROJECT")

src/basic_memory/mcp/tools/read_content.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from basic_memory.mcp.async_client import get_client
2121
from basic_memory.mcp.tools.utils import call_get, resolve_entity_id
2222
from basic_memory.schemas.memory import memory_url_path
23+
from basic_memory.telemetry import track_mcp_tool
2324
from basic_memory.utils import validate_project_path
2425

2526

@@ -200,6 +201,7 @@ async def read_content(
200201
HTTPError: If project doesn't exist or is inaccessible
201202
SecurityError: If path attempts path traversal
202203
"""
204+
track_mcp_tool("read_content")
203205
logger.info("Reading file", path=path, project=project)
204206

205207
async with get_client() as client:

src/basic_memory/mcp/tools/view_note.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from basic_memory.mcp.server import mcp
1010
from basic_memory.mcp.tools.read_note import read_note
11+
from basic_memory.telemetry import track_mcp_tool
1112

1213

1314
@mcp.tool(
@@ -54,7 +55,7 @@ async def view_note(
5455
HTTPError: If project doesn't exist or is inaccessible
5556
SecurityError: If identifier attempts path traversal
5657
"""
57-
58+
track_mcp_tool("view_note")
5859
logger.info(f"Viewing note: {identifier} in project: {project}")
5960

6061
# Call the existing read_note logic

0 commit comments

Comments
 (0)