Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 162 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"license": "",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.11.3",
"node-fetch": "^3.3.2"
"node-fetch": "^3.3.2",
"string-strip-html": "^13.4.12"
},
"devDependencies": {
"@types/node": "^22.15.17",
Expand Down
28 changes: 19 additions & 9 deletions src/tools/get-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
/* eslint-enable n/no-missing-import */
import { makeRestGetRequest } from '../common/utils.js';
import type { MwRestApiPageObject } from '../types/mwRestApi.js';
import { stripHtml } from 'string-strip-html';

enum ContentFormat {
noContent = 'noContent',
withSource = 'withSource',
withHtml = 'withHtml'
withHtml = 'withHtml',
withPlainText = 'withPlainText'
}

export function getPageTool( server: McpServer ): RegisteredTool {
Expand All @@ -29,16 +31,17 @@
);
}

async function handleGetPageTool( title: string, content: ContentFormat ): Promise<CallToolResult> {
async function handleGetPageTool( title: string, contentFormat: ContentFormat ): Promise<CallToolResult> {

Check warning on line 34 in src/tools/get-page.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 106. Maximum allowed is 100
let subEndpoint: string;
switch ( content ) {
switch ( contentFormat ) {
case ContentFormat.noContent:
subEndpoint = '/bare';
break;
case ContentFormat.withSource:
subEndpoint = '';
break;
case ContentFormat.withHtml:
case ContentFormat.withPlainText:
subEndpoint = '/with_html';
break;
}
Expand Down Expand Up @@ -66,11 +69,11 @@
}

return {
content: getPageToolResult( data )
content: getPageToolResult( data, contentFormat )
};
}

function getPageToolResult( result: MwRestApiPageObject ): TextContent[] {
function getPageToolResult( result: MwRestApiPageObject, contentFormat: ContentFormat ): TextContent[] {

Check warning on line 76 in src/tools/get-page.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 104. Maximum allowed is 100
const results: TextContent[] = [
{
type: 'text',
Expand All @@ -94,10 +97,17 @@
}

if ( result.html !== undefined ) {
results.push( {
type: 'text',
text: `HTML:\n${ result.html }`
} );
if ( contentFormat === ContentFormat.withHtml ) {
results.push( {
type: 'text',
text: `HTML:\n${ result.html }`
} );
} else if ( contentFormat === ContentFormat.withPlainText ) {
results.push( {
type: 'text',
text: `Text:\n${ stripHtml( result.html ).result }`
} );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be its own function

results.push( newFunction() )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parts of this will get rewritten in #38 anyway.

}

return results;
Expand Down