MCP funcionando: cliente conforme o protocolo, blocos na library e testes
A tinyblocks-mcp passa a ser uma library de blocos (categoria MCP, carregável pelas Bibliotecas): "servidor MCP %1 responde?", nome do servidor, ferramentas, nomes das ferramentas e "chame %2 do servidor MCP %1 com %3". Falha vira erro do TinyBlocks (pega no "se der erro" e no "tente obter"); só o "responde?" nunca falha. Cliente (Python embutido, tudo sob _tbmcp_ no __main__): - uma sessão por servidor: initialize uma vez, processo stdio vivo, reconecta se o servidor cair - stdio: shlex, ignora notificações e linhas que não são JSON-RPC, responde ping do servidor, tempo limite, stderr do servidor no erro - Streamable HTTP: Mcp-Session-Id, MCP-Protocol-Version, resposta JSON ou SSE, DELETE ao fechar - lista paginada; conteúdo de texto, imagem, recurso e estruturado; isError e erros JSON-RPC viram mensagens em português Corrige o carregamento do módulo (o vetor do xxd não termina em \0) e o build (lib-mcp depende de lib-python). O plugin examples/mcp saiu: os blocos vivem na library. test-mcp: servidor de teste próprio (tests/mcp_server.py) por stdio, HTTP e HTTP+SSE, com notificações no meio, ping do servidor, log que não é JSON, paginação, falhas e queda do servidor; e os blocos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d580005b1
commit
11d6e5317b
9 files changed
+986
-207
No files matched your search
@@ -102,7 +102,7 @@ LIB_LDFLAGS := -L$(ED_DIR)/build -L$(GX_DIR)/build -L$(SD_DIR)/build \
|
||||
.PHONY: all help debug release static shared example sdl2 clean run python-lib mcp-lib json \
|
||||
editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend test-editor \
|
||||
appdir appimage run-appimage icon \
|
||||
test-toml test-plugin test-blueprint test-a11y test-base64 test-curves test-meta test-ppm test-bmp test-png test-image test-vg test-svg test-jpg \
|
||||
test-toml test-plugin test-blueprint test-a11y test-mcp test-base64 test-curves test-meta test-ppm test-bmp test-png test-image test-vg test-svg test-jpg \
|
||||
test-syntax test-os test-value test-vars test-scratchblocks test-input test-stdlib test-regex test-markdown test-opentype \
|
||||
category-libs category-sos libs \
|
||||
lib-events lib-control lib-errors lib-input lib-operators lib-number lib-string lib-variables lib-vector lib-appearance lib-pen lib-fs lib-os \
|
||||
@@ -244,7 +244,7 @@ lib-sdl2:
|
||||
lib-python:
|
||||
$(MAKE) -C $(PY_DIR)
|
||||
|
||||
lib-mcp:
|
||||
lib-mcp: lib-python
|
||||
$(MAKE) -C $(MC_DIR)
|
||||
|
||||
libs: static lib-events lib-control lib-errors lib-operators lib-variables \
|
||||
@@ -430,17 +430,9 @@ $(BUILD)/python.so: examples/python/python.c static lib-python
|
||||
python-lib: static lib-python $(BUILD)/python.so ## Library Python (CPython embutido) -> build/python.so
|
||||
@echo "Build python OK: $(BUILD)/python.so"
|
||||
|
||||
# -- Library MCP (usa tinyblocks-python) ---
|
||||
$(BUILD)/mcp.so: examples/mcp/mcp.c static lib-mcp
|
||||
$(CC) $(CFLAGS_REL) \
|
||||
-I$(MC_DIR)/include -I$(PY_DIR)/include -Iinclude -fPIC -shared \
|
||||
$< -o $@ -L$(MC_DIR)/build -L$(PY_DIR)/build -L$(BUILD) \
|
||||
-ltinyblocks-mcp -ltinyblocks-python -ltinyblocks \
|
||||
'-Wl,-rpath,$$ORIGIN' '-Wl,-rpath,$(abspath $(MC_DIR)/build)' \
|
||||
'-Wl,-rpath,$(abspath $(PY_DIR)/build)'
|
||||
|
||||
mcp-lib: static lib-mcp $(BUILD)/mcp.so ## Library cliente MCP -> build/mcp.so
|
||||
@echo "Build mcp OK: $(BUILD)/mcp.so"
|
||||
# -- Library MCP (cliente MCP em Python embutido; blocos da categoria "MCP") ---
|
||||
mcp-lib: static lib-mcp ## Library MCP -> libraries/tinyblocks-mcp/build/libtinyblocks-mcp.so
|
||||
@echo "Build mcp OK: $(MC_DIR)/build/libtinyblocks-mcp.so"
|
||||
|
||||
ed-modules: ## Reconstroi so as libraries privadas do editor (hot reload)
|
||||
$(MAKE) -C $(ED_DIR)
|
||||
@@ -519,6 +511,20 @@ $(BUILD)/environ_test: tests/environ_test.c $(EN_DIR)/src/tb_environ.c static
|
||||
test-environ: $(BUILD)/environ_test ## Roda o teste da environ (ASan/UBSan)
|
||||
./$(BUILD)/environ_test
|
||||
|
||||
# -- Teste da library mcp (servidor de teste tests/mcp_server.py, stdio e HTTP) ---
|
||||
# Sem sanitizers: o CPython embutido nao convive bem com o ASan.
|
||||
ER_DIR := $(LIBDIR)/tinyblocks-errors
|
||||
$(BUILD)/mcp_test: tests/mcp_test.c tests/mcp_server.py $(ER_DIR)/src/tb_errors.c static lib-mcp
|
||||
@mkdir -p $(BUILD)
|
||||
$(CC) $(CFLAGS) -g -I$(MC_DIR)/include -I$(PY_DIR)/include -I$(ER_DIR)/include \
|
||||
tests/mcp_test.c $(ER_DIR)/src/tb_errors.c -o $@ \
|
||||
-Wl,--whole-archive $(LIB_A) -Wl,--no-whole-archive \
|
||||
-L$(MC_DIR)/build -L$(PY_DIR)/build -ltinyblocks-mcp -ltinyblocks-python -lm -rdynamic \
|
||||
'-Wl,-rpath,$(abspath $(MC_DIR)/build)' '-Wl,-rpath,$(abspath $(PY_DIR)/build)'
|
||||
|
||||
test-mcp: $(BUILD)/mcp_test ## Roda o teste do cliente MCP (stdio, HTTP e SSE)
|
||||
./$(BUILD)/mcp_test
|
||||
|
||||
# -- Teste da library a11y (arvore acessivel) ---
|
||||
$(BUILD)/a11y_test: tests/a11y_test.c $(A11Y_DIR)/src/tb_a11y.c $(A11Y_DIR)/include/tb_a11y.h static
|
||||
@mkdir -p $(BUILD)
|
||||
|
||||
Reference in new issue
Block a user