Skip to content

Commit 98dfe13

Browse files
committed
fixup! Introduce Kotlin integration tests
Signed-off-by: Sergey Karpov <[email protected]>
1 parent be02dcd commit 98dfe13

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ build/
33
!gradle/wrapper/gradle-wrapper.jar
44
!**/src/main/**/build/
55
!**/src/test/**/build/
6-
/src/jvmTest/resources/typescript-sdk/
76

87
### IntelliJ IDEA ###
98
.idea/modules.xml

kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/typescript/TypeScriptTestBase.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.modelcontextprotocol.kotlin.sdk.integration.typescript
22

3-
import org.junit.jupiter.api.AfterAll
43
import org.junit.jupiter.api.BeforeAll
54
import java.io.BufferedReader
65
import java.io.File
@@ -16,7 +15,11 @@ abstract class TypeScriptTestBase {
1615

1716
companion object {
1817
@JvmStatic
19-
protected val sdkDir = File("src/jvmTest/resources/typescript-sdk")
18+
private val tempRootDir: File =
19+
java.nio.file.Files.createTempDirectory("typescript-sdk-").toFile().apply { deleteOnExit() }
20+
21+
@JvmStatic
22+
protected val sdkDir: File = File(tempRootDir, "typescript-sdk")
2023

2124
/**
2225
* clone TypeScript SDK and install dependencies
@@ -27,7 +30,7 @@ abstract class TypeScriptTestBase {
2730
println("Cloning TypeScript SDK repository")
2831
if (!sdkDir.exists()) {
2932
val cloneCommand =
30-
"git clone --depth 1 https://github.com/modelcontextprotocol/typescript-sdk.git src/jvmTest/resources/typescript-sdk"
33+
"git clone --depth 1 https://github.com/modelcontextprotocol/typescript-sdk.git ${sdkDir.absolutePath}"
3134
val process = ProcessBuilder()
3235
.command("bash", "-c", cloneCommand)
3336
.redirectErrorStream(true)
@@ -42,17 +45,11 @@ abstract class TypeScriptTestBase {
4245
executeCommand("npm install", sdkDir)
4346
}
4447

45-
@JvmStatic
46-
@AfterAll
47-
fun removeTypeScriptSDK() {
48-
sdkDir.deleteRecursively()
49-
}
50-
5148
@JvmStatic
5249
protected fun executeCommand(command: String, workingDir: File): String {
5350
// Prefer running TypeScript via ts-node to avoid npx network delays on CI
5451
val process = ProcessBuilder()
55-
.command("bash", "-c", command)
52+
.command("bash", "-c", "TYPESCRIPT_SDK_DIR='${sdkDir.absolutePath}' $command")
5653
.directory(workingDir)
5754
.redirectErrorStream(true)
5855
.start()
@@ -126,7 +123,7 @@ abstract class TypeScriptTestBase {
126123

127124
protected fun executeCommandAllowingFailure(command: String, workingDir: File, timeoutSeconds: Long = 20): String {
128125
val process = ProcessBuilder()
129-
.command("bash", "-c", command)
126+
.command("bash", "-c", "TYPESCRIPT_SDK_DIR='${sdkDir.absolutePath}' $command")
130127
.directory(workingDir)
131128
.redirectErrorStream(true)
132129
.start()

kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/integration/utils/myClient.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
// @ts-ignore
2-
import {Client} from "../../../../../../../resources/typescript-sdk/src/client";
3-
// @ts-ignore
4-
import {StreamableHTTPClientTransport} from "../../../../../../../resources/typescript-sdk/src/client/streamableHttp.js";
5-
62
const args = process.argv.slice(2);
73
const serverUrl = args[0] || 'http://localhost:3001/mcp';
84
const toolName = args[1];
95
const toolArgs = args.slice(2);
106
const PROTOCOL_VERSION = "2024-11-05";
117

8+
// @ts-ignore
129
async function main() {
10+
// @ts-ignore
11+
const sdkDir = process.env.TYPESCRIPT_SDK_DIR;
12+
let Client: any;
13+
let StreamableHTTPClientTransport: any;
14+
if (sdkDir) {
15+
// @ts-ignore
16+
({Client} = await import(`${sdkDir}/src/client`));
17+
// @ts-ignore
18+
({StreamableHTTPClientTransport} = await import(`${sdkDir}/src/client/streamableHttp.js`));
19+
} else {
20+
// @ts-ignore
21+
({Client} = await import("../../../../../../../resources/typescript-sdk/src/client"));
22+
// @ts-ignore
23+
({StreamableHTTPClientTransport} = await import("../../../../../../../resources/typescript-sdk/src/client/streamableHttp.js"));
24+
}
1325
if (!toolName) {
1426
console.log('Usage: npx tsx myClient.ts [server-url] <tool-name> [tool-args...]');
1527
console.log('Using default server URL:', serverUrl);
@@ -44,6 +56,7 @@ async function main() {
4456
const tool = tools.find((t: { name: string; }) => t.name === toolName);
4557
if (!tool) {
4658
console.error(`Tool "${toolName}" not found`);
59+
// @ts-ignore
4760
process.exit(1);
4861
}
4962

@@ -80,6 +93,7 @@ async function main() {
8093

8194
} catch (error) {
8295
console.error('Error:', error);
96+
// @ts-ignore
8397
process.exit(1);
8498
} finally {
8599
await client.close();
@@ -89,5 +103,6 @@ async function main() {
89103

90104
main().catch(error => {
91105
console.error('Unhandled error:', error);
106+
// @ts-ignore
92107
process.exit(1);
93108
});

0 commit comments

Comments
 (0)