Skip to content

feat: middleware, MCP server, and CLI tool for v3.4#41

Merged
wrxck merged 1 commit intodevelopfrom
feat/v3.4-middleware-mcp-cli
Feb 21, 2026
Merged

feat: middleware, MCP server, and CLI tool for v3.4#41
wrxck merged 1 commit intodevelopfrom
feat/v3.4-middleware-mcp-cli

Conversation

@wrxck
Copy link
Owner

@wrxck wrxck commented Feb 21, 2026

Summary

  • Middleware systemapi.use(fn) for global middleware, api.middleware.on_message.use(fn) for scoped. Onion model with (ctx, next). Zero overhead when none registered.
  • MCP server — JSON-RPC 2.0 over stdio with 23 curated Telegram Bot API tools and telegram://bot/info resource. Works with Claude Code, Cursor, and other MCP clients.
  • CLI toolbin/tgbot with subcommands: send, info, updates, chat, ban, unban, mcp, run. Reads BOT_TOKEN from env. Installed via LuaRocks.
  • Version bump to 3.4-0 with new rockspec.

New files

File LOC Purpose
src/middleware.lua ~120 Middleware engine
src/mcp.lua ~375 MCP JSON-RPC server
bin/tgbot ~170 CLI tool
spec/middleware_spec.lua 14 tests Middleware ordering, scoping, early return, errors
spec/mcp_spec.lua 21 tests JSON-RPC parsing, tool dispatch, resources, serve loop
spec/cli_spec.lua 10 tests Arg parsing, subcommand validation, error handling
telegram-bot-lua-3.4-0.rockspec New rockspec with middleware, mcp modules and bin

Modified files

  • src/main.lua — version bump, loads middleware + mcp modules
  • src/handlers.lua — refactored process_update() to route through middleware chain
  • spec/test_helper.lua — added module mappings for middleware + mcp

Test plan

  • 45 new unit tests pass
  • All 567 existing tests still pass (612 total, 31 redis failures are pre-existing auth issue)
  • 0 luacheck warnings
  • MCP server verified end-to-end with piped JSON-RPC
  • Cross-spec contamination tested (middleware state cleanup)
  • CLI error handling tested (missing token, missing args, unknown commands)

Middleware: api.use(fn) for global middleware, api.middleware.on_message.use(fn)
for scoped middleware. Onion model with (ctx, next) signature. Zero overhead
when no middleware registered.

MCP: JSON-RPC 2.0 server over stdio with 23 curated Telegram Bot API tools
(send_message, ban_chat_member, etc.) and telegram://bot/info resource.
Compatible with Claude Code, Cursor, and other MCP clients.

CLI: bin/tgbot with subcommands (send, info, updates, chat, ban, unban, mcp,
run). Reads BOT_TOKEN from env.

Includes 45 new tests and v3.4-0 rockspec.
@wrxck wrxck merged commit 5470b3b into develop Feb 21, 2026
@wrxck wrxck deleted the feat/v3.4-middleware-mcp-cli branch February 21, 2026 02:26
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.

1 participant