Initial commit
This commit is contained in:
commit
56fb2646df
31 files changed
+3961
No files matched your search
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
import { config } from "dotenv";
|
||||
config();
|
||||
|
||||
export const BE_URL = process.env.BE_URL || 'https://api.liquidswap.com';
|
||||
@@ -0,0 +1,22 @@
|
||||
import { BE_URL } from "../constants.js";
|
||||
|
||||
export class Liquidswap {
|
||||
private readonly url = BE_URL
|
||||
|
||||
private async fetch(url: string) {
|
||||
const response = await fetch(`${this.url}${url}`)
|
||||
return response.json()
|
||||
}
|
||||
|
||||
public async getTokens() {
|
||||
const response = await this.fetch(`/coins/registered`)
|
||||
return response
|
||||
}
|
||||
|
||||
public async getPools() {
|
||||
const response = await this.fetch(`/pools/registered?networkId=1&cl=true`)
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
export const liquidswap = new Liquidswap()
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { config } from "dotenv";
|
||||
|
||||
config();
|
||||
|
||||
import { setupServer } from "./transports/setup-server.js";
|
||||
|
||||
const SSE_PORT = process.env.SSE_PORT || 3001;
|
||||
|
||||
// Start the server
|
||||
async function main() {
|
||||
await setupServer().then((app) => {
|
||||
app.start({
|
||||
transportType: "sse",
|
||||
sse: {
|
||||
endpoint: "/sse",
|
||||
port: Number(SSE_PORT),
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
import { Resource } from "../types/resources.js";
|
||||
|
||||
export const resourses: Resource[] = []
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Tool } from "../../types/tools.js";
|
||||
import { liquidswap } from "../../core/liquidswap.js";
|
||||
import { z } from "zod";
|
||||
|
||||
const getPools: Tool<typeof parameters>['execute'] = async () => {
|
||||
const data = await liquidswap.getPools();
|
||||
|
||||
return {
|
||||
type: "text",
|
||||
text: JSON.stringify(data, null, 2),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const parameters = z.object({});
|
||||
|
||||
|
||||
export const getPoolsTool: Tool<typeof parameters> = {
|
||||
name: "get_pools",
|
||||
description: "Get all pools registered on Liquidswap",
|
||||
execute: getPools,
|
||||
parameters,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./get-pools.js";
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Tool } from "../../types/tools.js";
|
||||
import { liquidswap } from "../../core/liquidswap.js";
|
||||
import { z } from "zod";
|
||||
|
||||
const getTokens: Tool<typeof parameters>['execute'] = async () => {
|
||||
const data = await liquidswap.getTokens();
|
||||
|
||||
return {
|
||||
type: "text",
|
||||
text: JSON.stringify(data, null, 2),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const parameters = z.object({});
|
||||
|
||||
|
||||
export const getTokensTool: Tool<typeof parameters> = {
|
||||
name: "get_tokens",
|
||||
description: "Get all tokens registered on Liquidswap",
|
||||
execute: getTokens,
|
||||
parameters,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./get-tokens.js";
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Tool } from "../types/tools.js";
|
||||
import { getTokensTool } from "./get-tokens/get-tokens.js";
|
||||
import { getPoolsTool } from "./get-pools/get-pools.js";
|
||||
|
||||
const tools: Tool<any>[] = [
|
||||
getTokensTool,
|
||||
getPoolsTool,
|
||||
];
|
||||
|
||||
export default tools;
|
||||
@@ -0,0 +1,72 @@
|
||||
import { resourses } from "../resources/all-resources.js";
|
||||
import { FastMCP } from "fastmcp";
|
||||
import * as fastmcp from "fastmcp";
|
||||
import { name, version } from "../version.js";
|
||||
import tools from "../tools/index.js";
|
||||
import { liquidswap } from "../core/liquidswap.js";
|
||||
|
||||
function setupServerHandlers(server: FastMCP) {
|
||||
for (const resource of resourses) {
|
||||
if ('arguments' in resource && resource.arguments) {
|
||||
server.addResourceTemplate({
|
||||
uriTemplate: `liquidswap://${resource.pathname}`,
|
||||
name: resource.name,
|
||||
mimeType: resource.mimeType,
|
||||
arguments: resource.arguments,
|
||||
load: async (args) => {
|
||||
return resource.handler(liquidswap, args);
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
server.addResource({
|
||||
uri: `liquidswap://${resource.pathname}`,
|
||||
name: resource.name,
|
||||
mimeType: resource.mimeType,
|
||||
async load() {
|
||||
return resource.handler(liquidswap, {});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
for (const tool of tools) {
|
||||
server.addTool(tool);
|
||||
}
|
||||
}
|
||||
|
||||
class FastMCPSession extends fastmcp.FastMCPSession {
|
||||
originalEmit = fastmcp.FastMCPSession.prototype.emit;
|
||||
}
|
||||
|
||||
Object.defineProperty(fastmcp.FastMCPSession.prototype, "originalEmit", {
|
||||
value: fastmcp.FastMCPSession.prototype.emit,
|
||||
writable: false,
|
||||
});
|
||||
|
||||
// suppress error event
|
||||
fastmcp.FastMCPSession.prototype.emit = function (
|
||||
this: FastMCPSession,
|
||||
event: any,
|
||||
...args: any[]
|
||||
) {
|
||||
if (event !== "error") {
|
||||
return this.originalEmit(event, ...args);
|
||||
}
|
||||
};
|
||||
|
||||
export async function setupServer() {
|
||||
const server = new FastMCP(
|
||||
{
|
||||
name,
|
||||
version
|
||||
},
|
||||
);
|
||||
|
||||
setupServerHandlers(server);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
export default setupServer;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Liquidswap } from "../core/liquidswap.js";
|
||||
import type { ResourceResult, ResourceTemplateArgument } from "fastmcp";
|
||||
|
||||
type ResourceTemplateArgumentsToObject<T extends {
|
||||
name: string;
|
||||
}[]> = {
|
||||
[K in T[number]["name"]]: string;
|
||||
};
|
||||
export type ResourceHandler<Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[]> = (santiment: Liquidswap, args: ResourceTemplateArgumentsToObject<Arguments>) => Promise<Arguments extends (ResourceResult | ResourceResult[]) ? (ResourceResult | ResourceResult[]) : ResourceResult>;
|
||||
export type Resource<Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[]> = {
|
||||
pathname: string;
|
||||
name: string;
|
||||
description: string;
|
||||
mimeType: `text/${string}` | `application/${string}`;
|
||||
handler: ResourceHandler<Arguments>;
|
||||
arguments?: Arguments;
|
||||
} | {
|
||||
pathname: string;
|
||||
name: string;
|
||||
description: string;
|
||||
mimeType: `text/${string}` | `application/${string}`;
|
||||
handler: ResourceHandler;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import type { Tool as fastmcpTool, ToolParameters } from "fastmcp";
|
||||
|
||||
export type Tool<Parameters extends ToolParameters = ToolParameters> = fastmcpTool<undefined, Parameters>;
|
||||
@@ -0,0 +1,2 @@
|
||||
export const version = "1.0.0";
|
||||
export const name = "liquidswap-mcp-server";
|
||||
Reference in new issue
Block a user