mirror of
https://github.com/kuhyx/todo-app.git
synced 2026-11-27 14:49:20 +01:00
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: <id8> 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 <noreply@anthropic.com>
This commit is contained in:
parent
7153630a2e
commit
711b69233a
136
lib/mcp/filing_skill.dart
Normal file
136
lib/mcp/filing_skill.dart
Normal file
@ -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: <id8>" 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/<origin repo name>`, 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: <what>`, in exactly those capitals.
|
||||
|
||||
## Closing a task
|
||||
|
||||
- Name the task in the commit that lands its work with a trailer line
|
||||
`Todo: <id8>` (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 `"<commit sha> 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<String, dynamic> 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<String, dynamic> Function(Object?) answer) =>
|
||||
low.setRequestHandler<JsonRpcRequest>(
|
||||
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<String, dynamic> json;
|
||||
|
||||
@override
|
||||
Map<String, dynamic>? get meta => null;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => json;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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: <id8>` 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` |
|
||||
|
||||
18
pubspec.lock
18
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:
|
||||
|
||||
@ -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
|
||||
|
||||
108
test/mcp/mcp_skill_test.dart
Normal file
108
test/mcp/mcp_skill_test.dart
Normal file
@ -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:<name>` 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<String, dynamic> json;
|
||||
|
||||
@override
|
||||
Map<String, dynamic>? get meta => null;
|
||||
|
||||
@override
|
||||
Map<String, dynamic> 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<Map<String, dynamic>> send(String method, Map<String, dynamic> 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<dynamic>;
|
||||
expect(skills, hasLength(1));
|
||||
final entry = skills.single as Map<String, dynamic>;
|
||||
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<String, dynamic>;
|
||||
expect(front['name'], last);
|
||||
expect(_name.hasMatch(last), isTrue, reason: last);
|
||||
expect(front['description'], isA<String>());
|
||||
expect(uri, isNot(contains(r'$')));
|
||||
|
||||
final files = (entry['resources'] as List<dynamic>)
|
||||
.cast<Map<String, dynamic>>();
|
||||
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: <id8>',
|
||||
'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<McpError>()),
|
||||
);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user