fix: add entity_type parameter to write_note MCP tool by phernandez · Pull Request #145 · basicmachines-co/basic-memory · GitHub
Skip to content

fix: add entity_type parameter to write_note MCP tool - #145

Merged
phernandez merged 4 commits into
mainfrom
claude/issue-144-20250618_141005
Jun 18, 2025
Merged

fix: add entity_type parameter to write_note MCP tool#145
phernandez merged 4 commits into
mainfrom
claude/issue-144-20250618_141005

Conversation

@phernandez

Copy link
Copy Markdown
Member

Fixes #144

Summary

  • Add optional entity_type parameter with default "note"
  • Replace hardcoded entity_type="note" with parameter
  • Add comprehensive tests for different entity types
  • Ensure backward compatibility with default behavior

Test Plan

  • Run just test to verify all tests pass
  • Run just lint and just format for code quality
  • Test creating notes with different entity types via MCP
  • Verify existing functionality unchanged

Generated with Claude Code

@CLAassistant

CLAassistant commented Jun 18, 2025

Copy link
Copy Markdown

@phernandez

Copy link
Copy Markdown
Member Author

@claude lets add a test also that does not set an entity_type on the write_note tool call but sets one in the embedded note frontmatter. We want to make sure that is respected also.

Example:

note = dedent("""
        ---
        title: Test Guide
        type: guide
        permalink: guides/test-guide
        tags:
        - guide
        - documentation
        ---
        
        # Guide Content
        This is a guide
        """

await write_note.fn(
        title="Test Guide",
        folder="guides",
        content=note
    )

This should have a type of "guilde"

@claude

claude Bot commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

Claude finished @phernandez's task —— View job


Todo List

  • Read existing test file to understand patterns
  • Read write_note tool implementation
  • Add new test case for frontmatter entity_type handling
  • Run tests to verify functionality (Unable to run tests - no Bash permissions)
  • Commit changes to PR branch

Summary

I've successfully added the requested test case test_write_note_respects_frontmatter_entity_type that verifies:

  • When write_note.fn() is called without the entity_type parameter
  • But the content includes frontmatter with type: guide
  • The frontmatter type is respected (result should be "guide", not the default "note")

The test follows the same patterns as existing tests and includes proper assertions to verify the behavior. The changes have been committed to the PR branch.

Test Details:

  • Creates content with frontmatter containing type: guide
  • Calls write_note.fn() without passing entity_type parameter
  • Verifies the resulting entity has type: guide in the frontmatter
  • Ensures all other content (title, tags, etc.) is preserved correctly

You can run just test to verify all tests pass, including the new test case.

@phernandez

Copy link
Copy Markdown
Member Author

@claude it looks like a test failed in the last job

@claude

claude Bot commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

claude Bot and others added 4 commits June 18, 2025 16:40
- Add optional entity_type parameter with default "note"
- Update function signature and docstring
- Replace hardcoded entity_type="note" with parameter
- Add comprehensive tests for different entity types
- Ensure backward compatibility with default behavior

Fixes #144

Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
Add test_write_note_respects_frontmatter_entity_type to verify that
when write_note is called without entity_type parameter, but the
content includes frontmatter with a 'type' field, that type is
respected instead of defaulting to 'note'.

Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
The test had a malformed YAML frontmatter delimiter (-- instead of ---) 
which was causing parsing failures. This fixes the test to use proper 
YAML frontmatter formatting.

Co-authored-by: Paul Hernandez <phernandez@users.noreply.github.com>
- Add frontmatter type extraction in EntityService.create_entity() and update_entity()
- Override schema.entity_type when content frontmatter contains 'type' field
- Fix lint error in alembic/env.py with noqa comment
- Update test formatting for consistency
- Ensures write_note respects both parameter and frontmatter entity_type values

Fixes #144

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@phernandez
phernandez force-pushed the claude/issue-144-20250618_141005 branch from 6d12c7b to 876fc70 Compare June 18, 2025 21:40
@phernandez
phernandez merged commit 7789864 into main Jun 18, 2025
@phernandez
phernandez deleted the claude/issue-144-20250618_141005 branch June 18, 2025 22:10
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.

[BUG] write_note MCP tool ignores entity_type parameter and forces all entities to type "note"

2 participants