refactor: rename request methods to remove send prefix (#161)

* refactor: rename request methods to remove send prefix

Following the MCP TS SDK convention where request methods don't have
the "send" prefix (reserved for notifications):

- App.sendMessage() → App.message()
- App.sendOpenLink() → App.openLink()
- AppBridge.sendResourceTeardown() → AppBridge.resourceTeardown()

The old method names are kept as deprecated aliases for backwards
compatibility.

Updated all examples to use the new method names.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* test: add tests for deprecated method aliases

- Update existing tests to use new method names (message, openLink)
- Add tests verifying deprecated aliases are same reference as new methods
- Add tests verifying deprecated aliases still work functionally

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: rename message→sendMessage, resourceTeardown→teardownResource

- App.message() → App.sendMessage() (with deprecated message alias)
- AppBridge.resourceTeardown() → AppBridge.teardownResource() (with deprecated aliases)

This better follows the pattern where methods that send data have 'send' or action verb prefix.

* fix: update examples to use sendMessage instead of message

* fix: update basic-host to use teardownResource

* fix: update threejs-server to use sendMessage

* refactor: remove deprecated app.message alias

The app.message alias was removed since sendMessage is the correct name.
sendResourceTeardown already exists in AppBridge.

* refactor: remove resourceTeardown alias, keep only sendResourceTeardown

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Olivier Chafik 2025-12-16 22:07:06 +00:00 • committed by GitHub
commit 2dd223b611
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -373,7 +373,7 @@ describe("App <-> AppBridge integration", () => {
await newBridgeTransport.close();
});
it("sendResourceTeardown triggers app.onteardown", async () => {
it("teardownResource triggers app.onteardown", async () => {
let teardownCalled = false;
app.onteardown = async () => {
teardownCalled = true;
@ -381,12 +381,12 @@ describe("App <-> AppBridge integration", () => {
};
await app.connect(appTransport);
await bridge.sendResourceTeardown({});
await bridge.teardownResource({});
expect(teardownCalled).toBe(true);
});
it("sendResourceTeardown waits for async cleanup", async () => {
it("teardownResource waits for async cleanup", async () => {
const cleanupSteps: string[] = [];
app.onteardown = async () => {
cleanupSteps.push("start");
@ -396,7 +396,7 @@ describe("App <-> AppBridge integration", () => {
};
await app.connect(appTransport);
await bridge.sendResourceTeardown({});
await bridge.teardownResource({});
expect(cleanupSteps).toEqual(["start", "done"]);
});
@ -481,7 +481,7 @@ describe("App <-> AppBridge integration", () => {
expect(result.isError).toBe(true);
});
it("app.sendOpenLink triggers bridge.onopenlink and returns result", async () => {
it("app.openLink triggers bridge.onopenlink and returns result", async () => {
const receivedLinks: string[] = [];
bridge.onopenlink = async (params) => {
receivedLinks.push(params.url);
@ -489,24 +489,51 @@ describe("App <-> AppBridge integration", () => {
};
await app.connect(appTransport);
const result = await app.sendOpenLink({ url: "https://example.com" });
const result = await app.openLink({ url: "https://example.com" });
expect(receivedLinks).toEqual(["https://example.com"]);
expect(result).toEqual({});
});
it("app.sendOpenLink returns error when host denies", async () => {
it("app.openLink returns error when host denies", async () => {
bridge.onopenlink = async () => {
return { isError: true };
};
await app.connect(appTransport);
const result = await app.sendOpenLink({ url: "https://blocked.com" });
const result = await app.openLink({ url: "https://blocked.com" });
expect(result.isError).toBe(true);
});
});
describe("deprecated method aliases", () => {
beforeEach(async () => {
await bridge.connect(bridgeTransport);
await app.connect(appTransport);
});
it("app.sendOpenLink is an alias for app.openLink", async () => {
expect(app.sendOpenLink).toBe(app.openLink);
});
it("bridge.sendResourceTeardown is a deprecated alias for bridge.teardownResource", () => {
expect(bridge.sendResourceTeardown).toBe(bridge.teardownResource);
});
it("app.sendOpenLink works as deprecated alias", async () => {
const receivedLinks: string[] = [];
bridge.onopenlink = async (params) => {
receivedLinks.push(params.url);
return {};
};
await app.sendOpenLink({ url: "https://example.com" });
expect(receivedLinks).toEqual(["https://example.com"]);
});
});
describe("ping", () => {
it("App responds to ping from bridge", async () => {
await bridge.connect(bridgeTransport);