Repository navigation
fix(tasks): unwrap inner "fields" key when parsing tasks.task.getFields - #4
Open
anticafeformat-dev wants to merge 1 commit into
Open
anticafeformat-dev wants to merge 1 commit into
anticafeformat-dev wants to merge 1 commit into
Conversation
Bitrix REST returns `tasks.task.getFields` as `{result: {fields: {ID:..., TITLE:..., DEADLINE:..., ...}}}` (the field map is nested under a `fields` key inside `result`). After `callApi` strips the outer `result`, the parser receives `{fields: {...}}` — but `parseTaskFields` iterates the top-level entries and treats `fields` itself as the only field, throwing "Invalid task field definition" for the inner map.
The downstream effect is that `create_task`'s `fields` validation in the MCP adapter (which calls `getTaskFields()` to build the allowed-field set) sees only one available field name (`fields`), so any real Bitrix field name passed by the caller — `DEADLINE`, `PRIORITY`, `PARENT_ID`, etc. — fails with `Unknown task fields`.
This patch unwraps the `fields` key when present, so iteration runs over the actual field map.
## Verification
```
$ get_task_fields
# Before: { "fields": { "fields": { ID:..., TITLE:..., DEADLINE:..., ... } } }
# (one top-level key, parsing breaks)
# After: 65 real Bitrix task fields visible
$ create_task title="..." responsible_id=1 fields={DEADLINE: "2026-05-15T18:00:00+03:00", PRIORITY: "2"}
# Before: throws "Unknown task fields: [DEADLINE, PRIORITY]"
# After: task created with deadline + priority set as requested
```
This is independent from PRs stemirkhan#1 (capabilities shape), stemirkhan#2 (tools/call result envelope), and stemirkhan#3 (task field expansion) — all four are MCP/Bitrix integration fixes that arose during real-world deployment but each in a different code path. Can be merged in any order.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Bitrix REST returns
tasks.task.getFieldsas:{ "result": { "fields": { "ID": {...}, "TITLE": {...}, "DEADLINE": {...}, "PRIORITY": {...}, ... } } }After
callApistrips the outerresult,parseTaskFieldsreceives{fields: {...}}— but it iterates the top-level entries and treatsfieldsitself as the only field. The innervalueis the real field map (a large nested object), so the existingif (!value || typeof value !== "object" || Array.isArray(value))check passes — and the parser silently produces{fields: {ID:..., TITLE:..., ...}}with one top-level key.The downstream effect lands in the MCP adapter
createTask.ts, which callsgetTaskFields()to build the allowed-field set for input validation:availableFieldsends up as{fields: {...}}— the only allowed name isfields. Any real Bitrix field passed by the caller (DEADLINE,PRIORITY,PARENT_ID,START_DATE_PLAN, etc.) hits theunknownFieldsbranch and is rejected withUnknown task fields. This makes thecreate_tasktool'sfieldsparameter effectively unusable for setting deadlines or any other field beyond the four flat ones (title,description,responsible_id,group_id).Fix
Unwrap the inner
fieldskey when present, so iteration runs over the actual field map:The fallback (use
recorddirectly if nofieldskey) preserves backward compatibility for any future Bitrix portal that returns the flat shape.Verification
Note
This is independent from PRs #1 (capabilities shape), #2 (tools/call result envelope), and #3 (task field expansion in select). Four orthogonal fixes that arose during real-world MCP integration deployment. Can be merged in any order.