Share one implementation between CLI commands and MCP tools
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- csharp
- 领域
- backend-api-design, cli, tooling
调研方向
阅读 AGENTS.md 和 Features/Mcp/McpHostCommand.cs 中的注册,然后检查 migration slice 1 的 LeaveUpdateService 以及 Timesheet 更新 CLI 和 MCP 适配器。完成的标准是适配器使用一个共享服务,架构测试和一致性测试强制执行委托,并且既有的 --json wire 形状保持不变。
由索引模型根据 Issue 内容生成。
描述
Why
47 MCP tools (18 default, 29 accounting-gated) are registered in Features/Mcp/McpHostCommand.cs. Only four share a service with their CLI counterpart (LeaveCreateService, LeaveUpdateService, LeaveBalanceImportService, WeekCoverageService). The other 43 re-implement the orchestration the CLI command already does, so every fix lands twice or, as with #21, only once. AGENTS.md already states the rule ("MCP delegates to the same service"); this issue makes the codebase follow it and adds a test that keeps it that way.
Inventory (where sharing is missing)
| MCP tool | CLI command | Today |
|---|---|---|
| GetTimesheets | ts get |
duplicate; MCP skips weekends, CLI does not |
| CreateTimesheet | ts create |
duplicate; CLI also resolves rate, category, deducted time |
| UpdateTimesheet | ts update |
duplicate, destructive (#21) |
| DeleteTimesheet / AcceptSuggestedTimesheet | ts delete / ts accept |
duplicate; empty-response handling differs |
| GetSuggestedTimesheets | ts suggest |
duplicate; note this refreshes server state, it is not read-only |
| CheckWeek | ts check |
shared service, duplicated projection |
| SearchClients / GetProjectsForClient / GetClientRate / GetCrmBookings / ListIterations | client search / project list / rate get / booking list / iteration list |
duplicate; missing-rate result differs |
| GetLeaveEntries / GetLeaveBalance / GetLeaveBalanceStatus | leave list / leave balance / leave balances status |
duplicate |
| All accounting tools (invoices, receipts, credit notes, products, rates, unbilled, recurring, query, summary, prepaid) | matching tp commands |
duplicate; prepaid calculation lives in TimeProApiClient |
| GetInvoicesByClient, GetUnpaidInvoicesByClient, ListCategories, ListBillableTypes, ListAllSkus | none | MCP-only, violates the "CLI first" rule |
| none | leave cancel |
CLI-only |
Target architecture
- Per feature:
Services/with a request record, result record and a service that owns validation, defaults, lookups, read-merge and API orchestration. No single giant service. - CLI command = parse settings, build request, call service, render table or JSON, choose exit code.
- MCP tool = bind args, build the same request, call the same service, serialize the same result record. Never shell out to
tp. - One result type feeds both
--jsonand MCP structured content. One serializer policy (OutputHelperomits nulls and stringifies enums; MCP classes currently differ). - One application error type (category, nullable API status, safe message, recovery hint,
mayHaveBeenApplied). CLI maps it to the{"error":{...}}envelope plus exit code; MCP maps it toCallToolResult.IsError = true. Today MCP returns{"error":"..."}strings that look like successful results. - Writes with previews follow the
LeaveUpdateServiceshape:PrepareAsync(no writes) thenApplyAsync. CLI--dry-runand MCPdryRuncall the same preparation. - Adapter-only: prompts,
--yes, table formatting, file vs base64 output, exit codes. MCP confirmations use client approval or elicitation; a model-suppliedconfirmed=trueis not consent.
Enforcement
- Architecture test: no
ITimeProApiClient,HttpClient, or console access fromFeatures/Mcp/Tools. Reflection can check dependencies; use Roslyn or IL inspection if delegation itself must be proven. - Every
[McpServerTool]maps to a shared service and a registered CLI command, with a temporary allowlist for unmigrated tools that may only shrink. - Adapter parity tests against the same fake service; snapshot
tools/listnames, schemas and annotations.
Migration order
| # | Slice | Size |
|---|---|---|
| 1 | TimesheetUpdateService, both update adapters (fixes #21; also home for #22 --iteration) |
M |
| 2 | Timesheet create (shared rate/category/location logic; no implicit MCP writes) | L |
| 3 | Delete, accept, and normalising leave/import outcomes | M |
| 4 | Timesheet reads, suggestions, week coverage (explicit weekend policy) | M |
| 5 | Prepaid and accounting reads (move prepaid maths out of TimeProApiClient) |
M each |
| 6 | Lookups and the MCP-only / CLI-only gaps above | S each |
| 7 | Remove allowlist and legacy projections | S |
Do not change established --json wire shapes while extracting; schema changes are separate, explicit PRs. Do this before the SDK upgrade (#39).
- 主要语言
- C#
- 星标
- 3
- 派生
- 0
- 平均合并
- 6 分钟
- 30 天内合并 PR
- 1
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
SSWConsulting/TimePro.Tools 的其他 Issue
-
Priority: P3 Type: Refactor
难度 5/5 一周以上 新手友好度 38/100
SSWConsulting/TimePro.Tools#101 ·
-
Priority: P3 Type: Refactor
难度 4/5 3-5 天 新手友好度 42/100
SSWConsulting/TimePro.Tools#100 ·
-
Priority: P3 Type: Refactor
难度 5/5 一周以上 新手友好度 35/100
-
Priority: P2 Type: Refactor
难度 5/5 一周以上 新手友好度 35/100
-
Priority: P2 Type: Bug Type: Refactor
难度 5/5 一周以上 新手友好度 38/100
查看 SSWConsulting/TimePro.Tools 的全部 Issue
相似的 Issue
-
is:bug is:FQNIssue
难度 2/5 1-3 小时 新手友好度 72/100
nunit/nunit3-vs-adapter#1527 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
bug effort:S P3
难度 2/5 1-3 小时 新手友好度 72/100
nightscout/nocturne#2840 ·
维护者通常 1 天内回复
-
track:release
难度 2/5 1-3 小时 新手友好度 80/100
-
[Bug] [Go] Ack returns nil when the server answers with a non-OK status可能已有人在做 @leizhiyuan 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
apache/rocketmq-clients#1465 ·
维护者通常 2 天内回复