Skip to content

feat(mcp): add basic_memory_diagnostics tool for version and system info#963

Merged
phernandez merged 7 commits into
mainfrom
feat/187-diagnostics-tool
Jul 15, 2026
Merged

feat(mcp): add basic_memory_diagnostics tool for version and system info#963
phernandez merged 7 commits into
mainfrom
feat/187-diagnostics-tool

Conversation

@groksrc

@groksrc groksrc commented Jun 11, 2026

Copy link
Copy Markdown
Member

Closes #187

Summary

Adds the read-only basic_memory_diagnostics MCP tool for support and troubleshooting. The report includes:

  • Basic Memory package version and API version.
  • Python, platform, and architecture information.
  • The resolved config.json path and its contents when present.
  • Redaction of cloud_api_key and credentials embedded in database_url.

The tool intentionally omits a hand-maintained tool inventory, following the issue discussion.

Safety and compatibility

  • Preserves the public basic_memory.__api_version__ attribute and corrects its stale value from v0 to v2.
  • Resolves the config path without constructing ConfigManager, so calling diagnostics does not create or chmod directories.
  • Preserves IPv6 brackets when redacting database URLs.
  • Conservatively redacts credentials even when a URL authority is malformed.
  • Handles missing, unreadable, malformed, and non-object config files without exposing unredacted content.
  • Suppresses duplicated structured output for the Markdown report.
  • Declares the complete read-only MCP annotation contract and participates in the central tool signature/annotation tests.

Testing

  • uv run pytest -q tests/mcp/test_tool_basic_memory_diagnostics.py tests/mcp/test_tool_contracts.py — 32 passed.
  • The diagnostics implementation reached 100% line coverage in the focused run.
  • uv run ruff check on changed files — passed.
  • uv run ty check on changed files — passed.
  • just fast-check — passed (with the repository's existing Python 3.14 asyncio deprecation diagnostics).

Files changed

File Change
src/basic_memory/__init__.py Corrects the preserved API version to v2
src/basic_memory/mcp/tools/__init__.py Registers and exports the diagnostics tool
src/basic_memory/mcp/tools/basic_memory_diagnostics.py Implements the read-only, redacted diagnostic report
tests/mcp/test_tool_basic_memory_diagnostics.py 28 behavior, error, redaction, and side-effect tests
tests/mcp/test_tool_contracts.py Locks the tool signature and directory annotations

Generated with Claude Code; maintainer hardening by Basic Machines.

@groksrc
groksrc marked this pull request as ready for review June 11, 2026 07:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29be0299f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/mcp/tools/basic_memory_diagnostics.py
groksrc added a commit that referenced this pull request Jun 11, 2026
Extends the existing _SECRET_FIELDS redaction to also strip the
user:password userinfo component from any URL-bearing config fields
(database_url) before surfacing them in diagnostics output. Adds
_redact_url() helper and a _URL_FIELDS set so future credential-bearing
URL fields are easy to add. Postgres passwords no longer leak to MCP
clients or support transcripts; host/port/db-name remain visible.

Fixes the P1 security finding raised in review of PR #963.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
Comment thread tests/mcp/test_tool_basic_memory_diagnostics.py Fixed
Comment thread tests/mcp/test_tool_basic_memory_diagnostics.py Fixed
groksrc added a commit that referenced this pull request Jun 11, 2026
…d structured output

- Remove orphaned __api_version__ ('v0' since 2025; real API routes are /v2,
  and nothing else reads the constant)
- output_schema=None so FastMCP doesn't duplicate the markdown report into
  structuredContent (halves the payload)
- Add title/tags annotations so #963 and #968 are merge-order independent

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
@groksrc groksrc added the On Hold Don't review or merge. Work is pending label Jun 12, 2026
@groksrc

groksrc commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

This is tested and good to go, but needs to ship in v0.next and we have a maintenance release ahead of it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new read-only MCP diagnostics tool intended to help troubleshoot Basic Memory installations by reporting version/system details and a redacted view of the config file.

Changes:

  • Added basic_memory_diagnostics MCP tool that returns a markdown diagnostics report (version/system/config).
  • Registered the tool in the MCP tools package init.
  • Added unit tests for diagnostics output and redaction helpers.
  • Modified basic_memory/__init__.py by removing __api_version__.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/basic_memory/mcp/tools/basic_memory_diagnostics.py New diagnostics MCP tool + helpers for redacting secrets/URL credentials.
src/basic_memory/mcp/tools/__init__.py Registers the new diagnostics tool for MCP enumeration.
tests/mcp/test_tool_basic_memory_diagnostics.py Adds unit tests for diagnostics output and redaction behavior.
src/basic_memory/__init__.py Removes the package-level __api_version__ constant.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/basic_memory/__init__.py Outdated
Comment thread src/basic_memory/mcp/tools/basic_memory_diagnostics.py
Comment thread src/basic_memory/mcp/tools/basic_memory_diagnostics.py Outdated
Comment thread src/basic_memory/mcp/tools/basic_memory_diagnostics.py
Comment thread tests/mcp/test_tool_basic_memory_diagnostics.py
@phernandez phernandez removed the On Hold Don't review or merge. Work is pending label Jul 15, 2026
phernandez pushed a commit that referenced this pull request Jul 15, 2026
Extends the existing _SECRET_FIELDS redaction to also strip the
user:password userinfo component from any URL-bearing config fields
(database_url) before surfacing them in diagnostics output. Adds
_redact_url() helper and a _URL_FIELDS set so future credential-bearing
URL fields are easy to add. Postgres passwords no longer leak to MCP
clients or support transcripts; host/port/db-name remain visible.

Fixes the P1 security finding raised in review of PR #963.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
phernandez pushed a commit that referenced this pull request Jul 15, 2026
…d structured output

- Remove orphaned __api_version__ ('v0' since 2025; real API routes are /v2,
  and nothing else reads the constant)
- output_schema=None so FastMCP doesn't duplicate the markdown report into
  structuredContent (halves the payload)
- Add title/tags annotations so #963 and #968 are merge-order independent

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
@phernandez
phernandez force-pushed the feat/187-diagnostics-tool branch from 4d0566c to 2d8a996 Compare July 15, 2026 03:03
@phernandez

Copy link
Copy Markdown
Member

@codex review

@phernandez

Copy link
Copy Markdown
Member

recheck

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2d8a996ccf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

groksrc and others added 5 commits July 14, 2026 23:37
Adds a new read-only MCP tool `basic_memory_diagnostics` that surfaces:
- Basic Memory package version and API version (from __init__.py)
- Python version and platform/architecture details
- Config file path and full config.json contents (cloud_api_key redacted)

Resolves #187.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
Extends the existing _SECRET_FIELDS redaction to also strip the
user:password userinfo component from any URL-bearing config fields
(database_url) before surfacing them in diagnostics output. Adds
_redact_url() helper and a _URL_FIELDS set so future credential-bearing
URL fields are easy to add. Postgres passwords no longer leak to MCP
clients or support transcripts; host/port/db-name remain visible.

Fixes the P1 security finding raised in review of PR #963.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
CodeQL flags dotted-host substring checks against URLs
(py/incomplete-url-substring-sanitization); exact matches are also
stronger assertions.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
…d structured output

- Remove orphaned __api_version__ ('v0' since 2025; real API routes are /v2,
  and nothing else reads the constant)
- output_schema=None so FastMCP doesn't duplicate the markdown report into
  structuredContent (halves the payload)
- Add title/tags annotations so #963 and #968 are merge-order independent

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member

@codex review

recheck

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7be4f1d8b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/mcp/tools/basic_memory_diagnostics.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member

@codex review

recheck

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cef13fa564

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/mcp/tools/basic_memory_diagnostics.py Outdated
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez

Copy link
Copy Markdown
Member

@codex review

/recheck

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: ef6929852c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@phernandez
phernandez merged commit 14495ee into main Jul 15, 2026
25 checks passed
@phernandez
phernandez deleted the feat/187-diagnostics-tool branch July 15, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add diagnostic tool for version and system information

4 participants