Skip to content

Conversation

@Scra3
Copy link
Member

@Scra3 Scra3 commented Dec 22, 2025

Summary

  • Add new create MCP tool to create records in a collection
  • Accepts collectionName and attributes object
  • Handles LLM sending attributes as JSON string (preprocessing)
  • Activity logging with 'create' action
  • Returns the created record

Dependencies

This PR is based on #1387 (feat/delete) and should be merged after it.

Test plan

  • Unit tests for create tool (14 tests)
  • All mcp-server tests pass (349 tests)

🤖 Generated with Claude Code

@qltysh
Copy link

qltysh bot commented Dec 22, 2025

1 new issue

Tool Category Rule Count
qlty Structure Function with many parameters (count = 4): declareCreateTool 1

@Scra3 Scra3 mentioned this pull request Dec 22, 2025
2 tasks
@qltysh
Copy link

qltysh bot commented Dec 22, 2025

Qlty

Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/agent/src/agent.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@Scra3 Scra3 changed the base branch from feat/delete to main December 23, 2025 16:11
alban bertolini and others added 2 commits December 24, 2025 11:13
Add a new MCP tool to create records in a collection:
- Accepts collectionName and attributes object
- Handles LLM sending attributes as JSON string
- Activity logging with 'create' action
- Returns the created record

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Copy link
Member Author

@Scra3 Scra3 left a comment

Choose a reason for hiding this comment

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

PR Review Summary

Overview

This PR adds a new create tool and refactors existing tools to use a withActivityLog utility for centralized activity log lifecycle management. Overall good DRY refactoring.


🔴 Critical Issue (1)

Activity log failure blocks operations

File: with-activity-log.ts:34-37

If createPendingActivityLog throws (network error, auth issue, server unavailable), the entire operation fails before business logic runs. Activity logging should be non-blocking - users should still be able to perform operations even if Forest Admin server is temporarily unavailable.

Suggestion: Wrap createPendingActivityLog in try/catch and continue with operation even if it fails:

let activityLog;
try {
  activityLog = await createPendingActivityLog(...);
} catch (err) {
  logger('Error', `Failed to create activity log: ${err}`);
}
// Continue with operation

🟡 Important Issues (4)

1. Lost error context in list-related.ts

Lines 28-76

parseAgentError was removed from enhanceErrorWithContext. The original code extracted nested JSON API error details, now it only uses error.message. Users will see raw JSON error payloads instead of clean messages.

2. Inconsistent error parsing in list.ts

Lines 131-148

The error handling now relies on raw error message after withActivityLog already parsed it. When parseAgentError returns null, the original unparsed error is thrown, and the "Invalid sort" check may fail on nested JSON.

3. Silent schema fetch failure

File: list-related.ts:68-71

Empty catch block with no logging when schema fetch fails during error enhancement. Consider adding debug logging.

4. Inconsistent error handling patterns

list and list-related have extra try/catch outside withActivityLog, while create and describe-collection don't. This makes error handling architecture unclear.


💡 Suggestions

  1. describe-collection.ts:101 - Uses action: 'index' but this tool describes schema, not lists records. Consider adding a comment explaining this choice.

  2. create.ts:13-17 - Silent JSON parse fallback. Consider adding debug logging when JSON parsing fails.

  3. Missing test - No test for createPendingActivityLog failure in with-activity-log.test.ts.


✅ Strengths

  • Good DRY refactoring with withActivityLog utility
  • Smart LLM handling in attributesWithPreprocess (handles JSON strings)
  • Comprehensive test coverage for new utility
  • Proper test updates for refactored tools

Comment on lines 138 to 139
const toolNames = ['describeCollection', 'list', 'listRelated', 'create'];
this.logger('Info', `Registered ${toolNames.length} tools: ${toolNames.join(', ')}`);
Copy link
Member

Choose a reason for hiding this comment

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

That's bad 😅
Cna you make that dynamic

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes ofc

- registerToolWithLogging now returns the tool name
- All tools are logged in a single line after registration
- Added [MCP] prefix for consistent log formatting
- Updated agent.ts log message to use [MCP] prefix

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@VincentMolinie VincentMolinie merged commit 7961086 into main Dec 24, 2025
22 checks passed
@VincentMolinie VincentMolinie deleted the feat/create branch December 24, 2025 13:27
forest-bot added a commit that referenced this pull request Dec 24, 2025
forest-bot added a commit that referenced this pull request Dec 24, 2025
# @forestadmin/agent [1.70.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/[email protected]...@forestadmin/[email protected]) (2025-12-24)

### Features

* **mcp-server:** add create tool ([#1388](#1388)) ([7961086](7961086))

### Dependencies

* **@forestadmin/mcp-server:** upgraded to 1.4.0
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.

3 participants