Skip to content

Commit 7c85bbe

Browse files
committed
Add injectable DevelopersApi support and OAuth 2.0 tool
1 parent aefd45e commit 7c85bbe

28 files changed

Lines changed: 346 additions & 123 deletions

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The toolkit provides the following tools for agents to use:
2828
* `get-documentation-section-content`: Retrieves the complete content for a specific documentation section.
2929
* `get-documentation-page`: Retrieves the complete content of a specific documentation page.
3030
* `get-oauth10a-integration-guide`: Retrieves the comprehensive OAuth 1.0a integration guide.
31+
* `get-oauth20-integration-guide`: Retrieves the comprehensive OAuth 2.0 integration guide.
3132
* `get-openfinance-integration-guide`: Retrieves the comprehensive Open Finance integration guide.
3233

3334
### API Operations

modelcontextprotocol/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This MCP server acts as a bridge between MCP clients and Mastercard Developers r
1414
- List available Mastercard services
1515
- Query API specifications and their operations
1616
- Access documentation for each service
17-
- Retrieve integration guides for OAuth 1.0a and Open Finance
17+
- Retrieve integration guides for OAuth 1.0a, OAuth 2.0, and Open Finance
1818

1919
## Available Tools
2020

@@ -40,6 +40,8 @@ This MCP server acts as a bridge between MCP clients and Mastercard Developers r
4040

4141
- **`get-oauth10a-integration-guide`**: Retrieves the comprehensive OAuth 1.0a integration guide including step-by-step instructions, code examples, and best practices for Mastercard APIs.
4242

43+
- **`get-oauth20-integration-guide`**: Retrieves the comprehensive OAuth 2.0 integration guide including step-by-step instructions, code examples, and best practices for Mastercard APIs.
44+
4345
- **`get-openfinance-integration-guide`**: Retrieves the comprehensive Open Finance integration guide including setup instructions, API usage examples, and implementation best practices.
4446

4547
## Configuration Options

typescript/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1.4",
2+
"version": "0.1.5",
33
"name": "@mastercard/developers-agent-toolkit",
44
"homepage": "https://github.com/mastercard/developers-agent-toolkit",
55
"description": "Agent Toolkit for Mastercard Developers Platform",

typescript/src/modelcontextprotocol/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { tools } from '@/shared/tools';
33
import { ToolContext } from '@/shared/types';
44
import { version } from '../../package.json';
55

6+
export type { DevelopersApi, Tool, ToolContext } from '@/shared/types';
7+
export { tools } from '@/shared/tools';
8+
69
export interface MastercardDevelopersAgentToolkitConfig {
710
service?: string;
811
apiSpecification?: string;

typescript/src/shared/api/__tests__/index.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MastercardAPIClient } from '@/shared/api';
1+
import { defaultDevelopersApi, MastercardAPIClient } from '@/shared/api';
22
import fetch, { RequestInfo, Response } from 'node-fetch';
33

44
const mcd = (path: string) => {
@@ -8,6 +8,12 @@ const mcd = (path: string) => {
88
const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
99
jest.mock('node-fetch');
1010

11+
describe('defaultDevelopersApi', () => {
12+
it('uses the default MastercardAPIClient implementation', () => {
13+
expect(defaultDevelopersApi).toBeInstanceOf(MastercardAPIClient);
14+
});
15+
});
16+
1117
describe('MastercardAPIClient', () => {
1218
let client: MastercardAPIClient;
1319

typescript/src/shared/api/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { z } from 'zod';
22
import fetch from 'node-fetch';
33

4+
import type { DevelopersApi } from '@/shared/types';
5+
46
const PathSchema = z
57
.string()
68
.min(1, 'Path must be a non-empty string')
@@ -106,5 +108,4 @@ export class MastercardAPIClient {
106108
}
107109
}
108110

109-
const api = new MastercardAPIClient();
110-
export default api;
111+
export const defaultDevelopersApi: DevelopersApi = new MastercardAPIClient();

typescript/src/shared/tools/documentation/__tests__/getDocumentation.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import {
22
execute,
33
getParameters,
44
} from '@/shared/tools/documentation/getDocumentation';
5-
import api from '@/shared/api';
5+
import { createMockApi } from '@/tests/mockDevelopersApi';
66

7-
jest.mock<typeof api>('@/shared/api');
8-
9-
const mockApi = api as jest.Mocked<typeof api>;
7+
const mockApi = createMockApi();
108

119
describe('execute', () => {
1210
beforeEach(() => {
@@ -17,7 +15,7 @@ describe('execute', () => {
1715
const mockResult = 'mock documentation';
1816
mockApi.getDocumentation.mockResolvedValue(mockResult);
1917

20-
const result = await execute({}, { serviceId: 'test-service' });
18+
const result = await execute({}, mockApi, { serviceId: 'test-service' });
2119

2220
expect(mockApi.getDocumentation).toHaveBeenCalledWith('test-service');
2321
expect(result).toBe(mockResult);
@@ -27,7 +25,7 @@ describe('execute', () => {
2725
const mockResult = 'mock documentation';
2826
mockApi.getDocumentation.mockResolvedValue(mockResult);
2927

30-
const result = await execute({ serviceId: 'context-service' }, {});
28+
const result = await execute({ serviceId: 'context-service' }, mockApi, {});
3129

3230
expect(mockApi.getDocumentation).toHaveBeenCalledWith('context-service');
3331
expect(result).toBe(mockResult);

typescript/src/shared/tools/documentation/__tests__/getDocumentationPage.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import {
22
execute,
33
getParameters,
44
} from '@/shared/tools/documentation/getDocumentationPage';
5-
import api from '@/shared/api';
5+
import { createMockApi } from '@/tests/mockDevelopersApi';
66

7-
jest.mock<typeof api>('@/shared/api');
8-
9-
const mockApi = api as jest.Mocked<typeof api>;
7+
const mockApi = createMockApi();
108

119
describe('execute', () => {
1210
beforeEach(() => {
@@ -17,7 +15,7 @@ describe('execute', () => {
1715
const mockResult = 'mock documentation page content';
1816
mockApi.getDocumentationPage.mockResolvedValue(mockResult);
1917

20-
const result = await execute({}, { pagePath: '/test/page.md' });
18+
const result = await execute({}, mockApi, { pagePath: '/test/page.md' });
2119

2220
expect(mockApi.getDocumentationPage).toHaveBeenCalledWith('/test/page.md');
2321
expect(result).toBe(mockResult);

typescript/src/shared/tools/documentation/__tests__/getDocumentationSection.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import {
22
execute,
33
getParameters,
44
} from '@/shared/tools/documentation/getDocumentationSection';
5-
import api from '@/shared/api';
5+
import { createMockApi } from '@/tests/mockDevelopersApi';
66

7-
jest.mock<typeof api>('@/shared/api');
8-
9-
const mockApi = api as jest.Mocked<typeof api>;
7+
const mockApi = createMockApi();
108

119
describe('execute', () => {
1210
beforeEach(() => {
@@ -17,10 +15,10 @@ describe('execute', () => {
1715
const mockResult = 'mock documentation section content';
1816
mockApi.getDocumentationSection.mockResolvedValue(mockResult);
1917

20-
const result = await execute(
21-
{},
22-
{ serviceId: 'test-service', sectionId: 'test-section' }
23-
);
18+
const result = await execute({}, mockApi, {
19+
serviceId: 'test-service',
20+
sectionId: 'test-section',
21+
});
2422

2523
expect(mockApi.getDocumentationSection).toHaveBeenCalledWith(
2624
'test-service',
@@ -33,10 +31,9 @@ describe('execute', () => {
3331
const mockResult = 'mock documentation section content';
3432
mockApi.getDocumentationSection.mockResolvedValue(mockResult);
3533

36-
const result = await execute(
37-
{ serviceId: 'context-service' },
38-
{ sectionId: 'test-section' }
39-
);
34+
const result = await execute({ serviceId: 'context-service' }, mockApi, {
35+
sectionId: 'test-section',
36+
});
4037

4138
expect(mockApi.getDocumentationSection).toHaveBeenCalledWith(
4239
'context-service',

0 commit comments

Comments
 (0)