@access-mcp/shared 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/__tests__/utils.test.js +29 -29
- package/dist/base-server.d.ts +3 -3
- package/dist/base-server.js +11 -11
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,13 +20,13 @@ npm install @access-mcp/shared
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
import { BaseAccessServer, handleApiError } from
|
|
23
|
+
import { BaseAccessServer, handleApiError } from "@access-mcp/shared";
|
|
24
24
|
|
|
25
25
|
export class MyServer extends BaseAccessServer {
|
|
26
26
|
constructor() {
|
|
27
|
-
super(
|
|
27
|
+
super("my-server", "1.0.0");
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
// Implement required abstract methods
|
|
31
31
|
}
|
|
32
32
|
```
|
|
@@ -40,4 +40,4 @@ export class MyServer extends BaseAccessServer {
|
|
|
40
40
|
|
|
41
41
|
## License
|
|
42
42
|
|
|
43
|
-
MIT
|
|
43
|
+
MIT
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { describe, test, expect } from
|
|
2
|
-
import { sanitizeGroupId, formatApiUrl, handleApiError } from
|
|
3
|
-
describe(
|
|
4
|
-
describe(
|
|
5
|
-
test(
|
|
6
|
-
expect(sanitizeGroupId(
|
|
1
|
+
import { describe, test, expect } from "vitest";
|
|
2
|
+
import { sanitizeGroupId, formatApiUrl, handleApiError } from "../utils.js";
|
|
3
|
+
describe("Utils", () => {
|
|
4
|
+
describe("sanitizeGroupId", () => {
|
|
5
|
+
test("should remove invalid characters", () => {
|
|
6
|
+
expect(sanitizeGroupId("test@#$%")).toBe("test");
|
|
7
7
|
});
|
|
8
|
-
test(
|
|
9
|
-
expect(sanitizeGroupId(
|
|
8
|
+
test("should keep valid characters", () => {
|
|
9
|
+
expect(sanitizeGroupId("test.group-123")).toBe("test.group-123");
|
|
10
10
|
});
|
|
11
|
-
test(
|
|
12
|
-
expect(sanitizeGroupId(
|
|
11
|
+
test("should handle empty string", () => {
|
|
12
|
+
expect(sanitizeGroupId("")).toBe("");
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
|
-
describe(
|
|
16
|
-
test(
|
|
17
|
-
expect(formatApiUrl(
|
|
15
|
+
describe("formatApiUrl", () => {
|
|
16
|
+
test("should format API URL correctly", () => {
|
|
17
|
+
expect(formatApiUrl("1.0", "users")).toBe("/1.0/users");
|
|
18
18
|
});
|
|
19
|
-
test(
|
|
20
|
-
expect(formatApiUrl(
|
|
19
|
+
test("should handle empty endpoint", () => {
|
|
20
|
+
expect(formatApiUrl("2.0", "")).toBe("/2.0/");
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
|
-
describe(
|
|
24
|
-
test(
|
|
23
|
+
describe("handleApiError", () => {
|
|
24
|
+
test("should extract message from response data", () => {
|
|
25
25
|
const error = {
|
|
26
26
|
response: {
|
|
27
|
-
data: { message:
|
|
28
|
-
}
|
|
27
|
+
data: { message: "Custom error message" },
|
|
28
|
+
},
|
|
29
29
|
};
|
|
30
|
-
expect(handleApiError(error)).toBe(
|
|
30
|
+
expect(handleApiError(error)).toBe("Custom error message");
|
|
31
31
|
});
|
|
32
|
-
test(
|
|
32
|
+
test("should handle status error", () => {
|
|
33
33
|
const error = {
|
|
34
34
|
response: {
|
|
35
35
|
status: 404,
|
|
36
|
-
statusText:
|
|
37
|
-
}
|
|
36
|
+
statusText: "Not Found",
|
|
37
|
+
},
|
|
38
38
|
};
|
|
39
|
-
expect(handleApiError(error)).toBe(
|
|
39
|
+
expect(handleApiError(error)).toBe("API error: 404 Not Found");
|
|
40
40
|
});
|
|
41
|
-
test(
|
|
42
|
-
const error = { message:
|
|
43
|
-
expect(handleApiError(error)).toBe(
|
|
41
|
+
test("should handle error message", () => {
|
|
42
|
+
const error = { message: "Network error" };
|
|
43
|
+
expect(handleApiError(error)).toBe("Network error");
|
|
44
44
|
});
|
|
45
|
-
test(
|
|
45
|
+
test("should handle unknown error", () => {
|
|
46
46
|
const error = {};
|
|
47
|
-
expect(handleApiError(error)).toBe(
|
|
47
|
+
expect(handleApiError(error)).toBe("Unknown API error");
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
});
|
package/dist/base-server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Server } from
|
|
2
|
-
import { StdioServerTransport } from
|
|
3
|
-
import { AxiosInstance } from
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
4
|
export declare abstract class BaseAccessServer {
|
|
5
5
|
protected serverName: string;
|
|
6
6
|
protected version: string;
|
package/dist/base-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Server } from
|
|
2
|
-
import { StdioServerTransport } from
|
|
3
|
-
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from
|
|
4
|
-
import axios from
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import axios from "axios";
|
|
5
5
|
export class BaseAccessServer {
|
|
6
6
|
serverName;
|
|
7
7
|
version;
|
|
@@ -9,7 +9,7 @@ export class BaseAccessServer {
|
|
|
9
9
|
server;
|
|
10
10
|
transport;
|
|
11
11
|
_httpClient;
|
|
12
|
-
constructor(serverName, version, baseURL =
|
|
12
|
+
constructor(serverName, version, baseURL = "https://support.access-ci.org/api") {
|
|
13
13
|
this.serverName = serverName;
|
|
14
14
|
this.version = version;
|
|
15
15
|
this.baseURL = baseURL;
|
|
@@ -28,12 +28,12 @@ export class BaseAccessServer {
|
|
|
28
28
|
get httpClient() {
|
|
29
29
|
if (!this._httpClient) {
|
|
30
30
|
const headers = {
|
|
31
|
-
|
|
31
|
+
"User-Agent": `${this.serverName}/${this.version}`,
|
|
32
32
|
};
|
|
33
33
|
// Add authentication if API key is provided
|
|
34
34
|
const apiKey = process.env.ACCESS_CI_API_KEY;
|
|
35
35
|
if (apiKey) {
|
|
36
|
-
headers[
|
|
36
|
+
headers["Authorization"] = `Bearer ${apiKey}`;
|
|
37
37
|
}
|
|
38
38
|
this._httpClient = axios.create({
|
|
39
39
|
baseURL: this.baseURL,
|
|
@@ -69,11 +69,11 @@ export class BaseAccessServer {
|
|
|
69
69
|
}
|
|
70
70
|
catch (error) {
|
|
71
71
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
72
|
-
console.error(
|
|
72
|
+
console.error("Error handling tool call:", errorMessage);
|
|
73
73
|
return {
|
|
74
74
|
content: [
|
|
75
75
|
{
|
|
76
|
-
type:
|
|
76
|
+
type: "text",
|
|
77
77
|
text: `Error: ${errorMessage}`,
|
|
78
78
|
},
|
|
79
79
|
],
|
|
@@ -86,12 +86,12 @@ export class BaseAccessServer {
|
|
|
86
86
|
}
|
|
87
87
|
catch (error) {
|
|
88
88
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
89
|
-
console.error(
|
|
89
|
+
console.error("Error reading resource:", errorMessage);
|
|
90
90
|
return {
|
|
91
91
|
contents: [
|
|
92
92
|
{
|
|
93
93
|
uri: request.params.uri,
|
|
94
|
-
mimeType:
|
|
94
|
+
mimeType: "text/plain",
|
|
95
95
|
text: `Error: ${errorMessage}`,
|
|
96
96
|
},
|
|
97
97
|
],
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./base-server.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
export * from "./utils.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./base-server.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
export * from "./utils.js";
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function sanitizeGroupId(groupId) {
|
|
2
|
-
return groupId.replace(/[^a-zA-Z0-9.-]/g,
|
|
2
|
+
return groupId.replace(/[^a-zA-Z0-9.-]/g, "");
|
|
3
3
|
}
|
|
4
4
|
export function formatApiUrl(version, endpoint) {
|
|
5
5
|
return `/${version}/${endpoint}`;
|
|
@@ -11,5 +11,5 @@ export function handleApiError(error) {
|
|
|
11
11
|
if (error.response?.status) {
|
|
12
12
|
return `API error: ${error.response.status} ${error.response.statusText}`;
|
|
13
13
|
}
|
|
14
|
-
return error.message ||
|
|
14
|
+
return error.message || "Unknown API error";
|
|
15
15
|
}
|