From 711b69233a8b5274f1b7b85ad43e98e4151c0cb7 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 27 Nov 2026 11:34:38 +0100 Subject: [PATCH] Serve task-filing rules as an MCP skill The todo MCP server now publishes `filing-tasks` through the MCP Skills extension (io.modelcontextprotocol/skills, 2026-07-28): the add_task fields, the MANUAL WORK REQUIRED title, the Todo: trailer and the close-the-task rule. mcp_dart 2.4.4 has no Skills API, so lib/mcp/filing_skill.dart registers the capability, skills/list, skills/get and the SKILL.md resource by hand. Claude Code 2.1.332 only asks for MCP skills when its remote flag tengu_wiggly_crystal is on, and it is off for this account, so /skills does not list todo:filing-tasks yet. The CLAUDE.md and md-file-conventions copies stay the source for claude -p workers. Also bumps crdt_sync 0.14.2 / crdt_sync_flutter 0.9.2 / sync_settings_ui 0.8.6, which the freshness gate requires (a file split and a per-instance temp file name; no wire-format change). Bug-class-check: test/mcp/mcp_skill_test.dart Co-Authored-By: Claude Opus 5.5 --- lib/mcp/filing_skill.dart | 136 +++++++++++++++++++++++++++++++++++ lib/mcp/todo_mcp_server.dart | 2 + mcp/README.md | 12 ++++ pubspec.lock | 18 ++--- pubspec.yaml | 8 +-- test/mcp/mcp_skill_test.dart | 108 ++++++++++++++++++++++++++++ 6 files changed, 271 insertions(+), 13 deletions(-) create mode 100644 lib/mcp/filing_skill.dart create mode 100644 test/mcp/mcp_skill_test.dart diff --git a/lib/mcp/filing_skill.dart b/lib/mcp/filing_skill.dart new file mode 100644 index 0000000..ec8802d --- /dev/null +++ b/lib/mcp/filing_skill.dart @@ -0,0 +1,136 @@ +import 'dart:convert'; + +import 'package:crdt_sync/crdt_sync.dart'; +import 'package:mcp_dart/mcp_dart.dart'; + +/// The MCP Skills extension (revision 2026-07-28). mcp_dart 2.4.4 has no +/// typed API for it, so this file wires its two methods by hand: a +/// capability under `extensions`, `skills/list` + `skills/get`, and the +/// SKILL.md served as a plain resource the client reads and hash-checks. +const kSkillsExtensionId = 'io.modelcontextprotocol/skills'; + +/// The skill's name; Claude Code lists it as `todo:filing-tasks`. +const kFilingSkillName = 'filing-tasks'; + +/// SKILL.md's address. The last directory segment must equal the name. +const kFilingSkillUri = 'skill://todo/$kFilingSkillName/SKILL.md'; + +const _description = + "File, track and close a task in kuhy's todo app: the add_task fields, " + 'the "MANUAL WORK REQUIRED: " title, the "Todo: " commit trailer ' + 'and closing with evidence. Use when asked to file, add or note a ' + 'task, when you find work you will not finish now, and before you ' + "call a task's work done."; + +// Kept in step with the copies in ~/.claude/CLAUDE.md and the +// md-file-conventions skill: `claude -p` board workers never load MCP +// skills, so those copies stay the source for them. +const _body = ''' +# Filing tasks in the todo app + +Tasks for kuhy's repos live in the todo app, never in TODO*.md files. + +## add_task fields + +- `repo`: `kuhyx/`, e.g. `kuhyx/todo-app`. +- `title`: one line naming the work. +- `body`: markdown with what / where / done / verify. +- `done_check`: a shell command run from the repo root, offline, under + 60 s, that exits 0 once the work is done. Its exit code settles it. +- `priority`: low | medium | high (default medium). +- `new_note: true` only when the task needs its own note; by default it + joins the repo's single open note as a `## title` section. + +## Work only kuhy can do + +A task that needs kuhy's manual work has a title that starts with +`MANUAL WORK REQUIRED: `, in exactly those capitals. + +## Closing a task + +- Name the task in the commit that lands its work with a trailer line + `Todo: ` (its 8-character id prefix). The post-commit hook runs + the task's done_check and closes it only on exit 0. +- A task still open after that commit, or one with `Check: manual`: + run its done_check yourself and only if it exits 0 call `close_task` + with evidence `" done_check exit 0"`. +- Never leave finished work's task open, and never close without + running its done_check. +'''; + +/// SKILL.md: frontmatter (JSON-quoted, which is valid YAML) then [_body]. +final String filingSkillMd = [ + '---', + 'name: ${jsonEncode(kFilingSkillName)}', + 'description: ${jsonEncode(_description)}', + '---', + _body, +].join('\n'); + +/// The skill's `skills/list` entry; its one file carries size and digest. +Map filingSkillEntry() { + final bytes = utf8.encode(filingSkillMd); + return { + 'uri': kFilingSkillUri, + 'frontmatter': {'name': kFilingSkillName, 'description': _description}, + 'resources': [ + { + 'uri': kFilingSkillUri, + 'size': bytes.length, + 'digest': 'sha256:${revisionOf(filingSkillMd)}', + }, + ], + }; +} + +/// Publishes the filing skill on [server]; call before it connects. +void registerFilingSkill(McpServer server) { + final low = server.server + ..registerCapabilities( + const ServerCapabilities(extensions: {kSkillsExtensionId: {}}), + ); + server.registerResource( + kFilingSkillName, + kFilingSkillUri, + (description: _description, mimeType: 'text/markdown'), + (uri, _) => ReadResourceResult( + contents: [ + TextResourceContents( + uri: kFilingSkillUri, + mimeType: 'text/markdown', + text: filingSkillMd, + ), + ], + ), + ); + void method(String name, Map Function(Object?) answer) => + low.setRequestHandler( + name, + (request, _) async => _Json(answer(request.params?['uri'])), + (id, params, meta) => + JsonRpcRequest(id: id, method: name, params: params, meta: meta), + ); + method( + 'skills/list', + (_) => { + 'skills': [filingSkillEntry()], + }, + ); + method('skills/get', (uri) { + if (uri == kFilingSkillUri) return {'skill': filingSkillEntry()}; + throw McpError(ErrorCode.resourceNotFound.value, 'no skill at $uri'); + }); +} + +/// A result whose JSON is already built. +class _Json implements BaseResultData { + const _Json(this.json); + + final Map json; + + @override + Map? get meta => null; + + @override + Map toJson() => json; +} diff --git a/lib/mcp/todo_mcp_server.dart b/lib/mcp/todo_mcp_server.dart index 9c2b73c..0952253 100644 --- a/lib/mcp/todo_mcp_server.dart +++ b/lib/mcp/todo_mcp_server.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:mcp_dart/mcp_dart.dart'; +import 'package:todo/mcp/filing_skill.dart'; import 'package:todo/mcp/request_guard.dart'; import 'package:todo/mcp/task_service.dart'; import 'package:todo/mcp/token_file.dart'; @@ -204,6 +205,7 @@ McpServer _server(TaskService tasks) { ['query'], tasks.search, ); + registerFilingSkill(server); return server; } diff --git a/mcp/README.md b/mcp/README.md index 835c1a6..1c932e8 100644 --- a/mcp/README.md +++ b/mcp/README.md @@ -16,6 +16,18 @@ task (`id8 status priority repo title created_by`); `get_task` prints `created_by` is `claude` for notes filed through `add_task` or the CLI and `kuhy` for everything else (a missing value reads as `kuhy`). +The server also publishes one skill through the MCP Skills extension +(`io.modelcontextprotocol/skills`, revision 2026-07-28): `filing-tasks`, +which Claude Code lists as `todo:filing-tasks`. It holds the `add_task` field +rules, the `MANUAL WORK REQUIRED:` title rule, the `Todo: ` commit trailer +and the close-the-task rule. mcp_dart 2.4.4 has no Skills API, so +`lib/mcp/filing_skill.dart` registers the capability, `skills/list`, +`skills/get` and the SKILL.md resource itself; the entry's sha256 and size are +computed from the served text. Claude Code 2.1.332 only asks for MCP skills +when its remote flag `tengu_wiggly_crystal` is on; it was off for kuhy's +account on 2026-11-27, so `/skills` does not list `todo:filing-tasks` yet. `claude -p` board workers never load MCP skills, so +`~/.claude/CLAUDE.md` and the `md-file-conventions` skill keep their copies. + | What | Where | |---|---| | Firebase seed (read once) | `~/.config/todo-mcp/firebase_auth.json` | diff --git a/pubspec.lock b/pubspec.lock index 717153a..52a644a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -109,20 +109,20 @@ packages: dependency: "direct main" description: path: crdt_sync_dart - ref: "crdt_sync_dart-v0.14.1" - resolved-ref: edd0f7a7882cb1d3904932ba94faa282d08165df + ref: "crdt_sync_dart-v0.14.2" + resolved-ref: "171a7f8ae34cec78df17a680e42878ca0b97c137" url: "https://github.com/kuhyx/utils" source: git - version: "0.14.1" + version: "0.14.2" crdt_sync_flutter: dependency: "direct main" description: path: crdt_sync_flutter - ref: "crdt_sync_flutter-v0.9.1" - resolved-ref: "48dc28ad97b97c787aba4479c3ce51aade6e86b5" + ref: "crdt_sync_flutter-v0.9.2" + resolved-ref: "41af57870207f80a5bf571f15544a08fddcbe7bf" url: "https://github.com/kuhyx/utils" source: git - version: "0.9.1" + version: "0.9.2" cross_file: dependency: transitive description: @@ -1101,11 +1101,11 @@ packages: dependency: "direct main" description: path: sync_settings_ui - ref: "sync_settings_ui-v0.8.5" - resolved-ref: abfb596d7ce2f28acfefbd55e7b3227257325261 + ref: "sync_settings_ui-v0.8.6" + resolved-ref: "41af57870207f80a5bf571f15544a08fddcbe7bf" url: "https://github.com/kuhyx/utils" source: git - version: "0.8.5" + version: "0.8.6" synchronized: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7d9c873..c62d475 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.106+1 +version: 1.0.107+1 environment: sdk: ^3.12.2 @@ -33,12 +33,12 @@ dependencies: crdt_sync: git: url: https://github.com/kuhyx/utils - ref: crdt_sync_dart-v0.14.1 + ref: crdt_sync_dart-v0.14.2 path: crdt_sync_dart crdt_sync_flutter: git: url: https://github.com/kuhyx/utils - ref: crdt_sync_flutter-v0.9.1 + ref: crdt_sync_flutter-v0.9.2 path: crdt_sync_flutter # The following adds the Cupertino Icons font to your application. @@ -111,7 +111,7 @@ dependencies: sync_settings_ui: git: url: https://github.com/kuhyx/utils - ref: sync_settings_ui-v0.8.5 + ref: sync_settings_ui-v0.8.6 path: sync_settings_ui url_launcher: 6.3.3 uuid: 4.6.0 diff --git a/test/mcp/mcp_skill_test.dart b/test/mcp/mcp_skill_test.dart new file mode 100644 index 0000000..1d20a15 --- /dev/null +++ b/test/mcp/mcp_skill_test.dart @@ -0,0 +1,108 @@ +// The task-filing skill over the MCP Skills extension (2026-07-28): the +// entry, the file list and the SKILL.md read must pass the same checks +// Claude Code runs before it lists `todo:` and loads it. +import 'dart:convert'; + +import 'package:crdt_sync/crdt_sync.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mcp_dart/mcp_dart.dart'; + +import 'mcp_harness.dart'; + +const _ext = 'io.modelcontextprotocol/skills'; +final _name = RegExp(r'^(?=.{1,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$'); + +class _Raw implements BaseResultData { + _Raw(this.json); + + final Map json; + + @override + Map? get meta => null; + + @override + Map toJson() => json; +} + +void main() { + late McpHarness h; + late McpClient c; + + setUp(() async { + h = McpHarness(); + await h.start(); + c = await h.connect(); + }); + tearDown(() => h.dispose()); + + Future> send(String method, Map p) => c + .request(JsonRpcRequest(id: 0, method: method, params: p), _Raw.new) + .then((r) => r.json); + + test('declares the extension on 2026-07-28', () { + expect(c.getProtocolVersion(), '2026-07-28'); + expect(c.getServerCapabilities()?.extensions?[_ext], isNotNull); + }); + + test('lists one valid entry and serves its SKILL.md', () async { + final list = await send('skills/list', {}); + final skills = list['skills'] as List; + expect(skills, hasLength(1)); + final entry = skills.single as Map; + final uri = entry['uri'] as String; + expect(uri, endsWith('/SKILL.md')); + final root = uri.substring(0, uri.length - '/SKILL.md'.length); + final last = root.substring(root.lastIndexOf('/') + 1); + final front = entry['frontmatter'] as Map; + expect(front['name'], last); + expect(_name.hasMatch(last), isTrue, reason: last); + expect(front['description'], isA()); + expect(uri, isNot(contains(r'$'))); + + final files = (entry['resources'] as List) + .cast>(); + final md = files.singleWhere((f) => f['uri'] == uri); + + final got = await send('skills/get', {'uri': uri}); + expect(got['skill'], entry); + + final read = await c.readResource(ReadResourceRequest(uri: uri)); + expect(read.contents, hasLength(1)); + final content = read.contents.single as TextResourceContents; + expect(content.uri, uri); + final bytes = utf8.encode(content.text); + expect(md['size'], bytes.length); + expect(md['digest'], 'sha256:${revisionOf(content.text)}'); + + // The frontmatter in the file parses to exactly the listed one. + final text = content.text; + expect(text, startsWith('---\n')); + final end = text.indexOf('\n---\n', 4); + final lines = text.substring(4, end).split('\n'); + final parsed = { + for (final l in lines) + l.substring(0, l.indexOf(':')): jsonDecode( + l.substring(l.indexOf(':') + 1).trim(), + ), + }; + expect(parsed, front); + + final body = text.substring(end + 5); + for (final rule in [ + 'add_task', + 'done_check', + 'MANUAL WORK REQUIRED: ', + 'Todo: ', + 'close_task', + ]) { + expect(body, contains(rule)); + } + }); + + test('skills/get on an unknown uri is an error', () async { + await expectLater( + send('skills/get', {'uri': 'skill://todo/nope/SKILL.md'}), + throwsA(isA()), + ); + }); +}